Trait Mapping

Source
pub trait Mapping {
    type Dom: Eq + Clone;
    type Cod: Eq + Clone;

    // Required method
    fn apply(&self, x: Self::Dom) -> Option<Self::Cod>;

    // Provided methods
    fn apply_to_ref(&self, x: &Self::Dom) -> Option<Self::Cod> { ... }
    fn is_set(&self, x: &Self::Dom) -> bool { ... }
}
Expand description

A functional mapping.

A mapping sends values of type Dom to values of type Cod. Unlike a function, a mapping need not be defined on its whole domain. A mapping is thus more like a partial function, but it does not even know its intended domain of definition, nor the codomain to which its image should restrict. If needed, that information should be provided separately as sets. Neither domain nor codomain are assumed to be finite.

This trait encompasses mappings that compute their values on the fly and mappings that own their data, say in the form of a vector or hash map. Achieving this flexiblity in Rust is delicate due to the sharp distinction between values and references, but as a user, deciding which method to call is simple enough. To evaluate at a point that you own and can consume, call apply. To evaluate at a point that you have only by reference or can’t consume, call apply_to_ref.

Required Associated Types§

Source

type Dom: Eq + Clone

Type of elements in domain of mapping.

Source

type Cod: Eq + Clone

Type of elements in codomain of mapping.

Required Methods§

Source

fn apply(&self, x: Self::Dom) -> Option<Self::Cod>

Applies the mapping at a point possibly in the domain.

Provided Methods§

Source

fn apply_to_ref(&self, x: &Self::Dom) -> Option<Self::Cod>

Applies the mapping at a reference to a point possibly in the domain.

The default implementation just calls apply after cloning. Mappings that own their data should give a more efficient implementation.

Source

fn is_set(&self, x: &Self::Dom) -> bool

Is the mapping defined at a point?

The default implementation just checks whether apply_to_ref returns something, but a more efficient implementation that avoids allocating should usually be given.

Implementors§

Source§

impl Mapping for SkelIndexedColumn

Source§

impl<'a, V, E, Ob, Mor, Map, Cod> Mapping for FpFunctorMorMap<'a, Map, Cod>
where V: Eq + Clone, E: Eq + Clone, Mor: Eq + Clone, Map: GraphMapping<DomV = V, DomE = E, CodV = Ob, CodE = Mor>, Cod: Category<Ob = Ob, Mor = Mor>,

Source§

type Dom = Path<V, E>

Source§

type Cod = Mor

Source§

impl<K, V, S> Mapping for HashColumn<K, V, S>
where K: Eq + Hash + Clone, V: Eq + Clone, S: BuildHasher,

Source§

type Dom = K

Source§

type Cod = V

Source§

impl<K, V, S> Mapping for IndexedHashColumn<K, V, S>
where K: Eq + Hash + Clone, V: Eq + Hash + Clone, S: BuildHasher,

Source§

type Dom = K

Source§

type Cod = V

Source§

impl<T: Eq + Clone> Mapping for VecColumn<T>

Source§

impl<T: Eq + Hash + Clone> Mapping for IndexedVecColumn<T>