Map

Trait Map 

Source
pub trait Map<C, T>: Default + FromIterator<(C, T)> {
    type Iter<'a>: Iterator<Item = (&'a C, &'a T)>
       where C: 'a,
             T: 'a,
             Self: 'a;
    type IntoEntries: Iterator<Item = (C, T)>;

    // Required methods
    fn get(&self, class: &C) -> Option<&T>;
    fn get_mut(&mut self, class: &C) -> Option<&mut T>;
    fn set(&mut self, class: C, value: T);
    fn iter(&self) -> Self::Iter<'_>;
    fn into_entries(self) -> Self::IntoEntries;

    // Provided methods
    fn singleton(class: C, value: T) -> Self { ... }
    fn contains(&self, class: &C) -> bool { ... }
    fn get_mut_or_insert_with(
        &mut self,
        class: &C,
        f: impl FnOnce() -> T,
    ) -> &mut T
       where C: Clone { ... }
    fn get_or_try_insert_with<E>(
        &mut self,
        class: &C,
        f: impl FnOnce() -> Result<T, E>,
    ) -> Result<&T, E>
       where C: Clone { ... }
}

Required Associated Types§

Source

type Iter<'a>: Iterator<Item = (&'a C, &'a T)> where C: 'a, T: 'a, Self: 'a

Source

type IntoEntries: Iterator<Item = (C, T)>

Required Methods§

Source

fn get(&self, class: &C) -> Option<&T>

Source

fn get_mut(&mut self, class: &C) -> Option<&mut T>

Source

fn set(&mut self, class: C, value: T)

Source

fn iter(&self) -> Self::Iter<'_>

Source

fn into_entries(self) -> Self::IntoEntries

Provided Methods§

Source

fn singleton(class: C, value: T) -> Self

Source

fn contains(&self, class: &C) -> bool

Source

fn get_mut_or_insert_with(&mut self, class: &C, f: impl FnOnce() -> T) -> &mut T
where C: Clone,

Source

fn get_or_try_insert_with<E>( &mut self, class: &C, f: impl FnOnce() -> Result<T, E>, ) -> Result<&T, E>
where C: Clone,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Map<(), T> for Unmapped<T>