Trait typemap_core::TypeMapSet[][src]

pub trait TypeMapSet: Sealed {
    fn try_set<T: 'static>(&mut self, value: T) -> bool;

    fn set<T: 'static>(&mut self, value: T)
    where
        Self: ContainsMut<T>
, { ... } }

The TypeMapSet trait allows for setting values of types in a typemap.

Required methods

fn try_set<T: 'static>(&mut self, value: T) -> bool[src]

Attempts to mutably set a value of a given type in the map.

This is mainly intended for the case where you don't require a type to be present, but would like to act on it if it is. Returns false if the type is not present in the map. On nightly, this should only occur if ContainsMut<T> is not implemented.

use typemap_core::{typemap, TypeMapGet, TypeMapSet};

let mut map = typemap!(u32 = 13u32);
assert!(map.try_set(42u32));
assert_eq!(map.get::<u32>(), &42);

// type is not present in map
assert!(!map.try_set(1u128));
Loading content...

Provided methods

fn set<T: 'static>(&mut self, value: T) where
    Self: ContainsMut<T>, 
[src]

Mutable sets a value of a given type in the map.

On nightly, you can only call this method if the type is actually present. (i.e. the map implements implements ContainsMut<T>)

Panics

This function panics if try_set would return false. This should only be possible on stable, so you can weed out potential panics by occasionally checking against nightly.

use typemap_core::{typemap, TypeMapGet, TypeMapSet};

let mut map = typemap!(&str = "");
map.set("Hello, world!");
println!("{}", map.get::<&str>());
Loading content...

Implementors

impl TypeMapSet for TyEnd[src]

impl<V: 'static, R: TypeMapSet> TypeMapSet for &Ty<V, R>[src]

impl<V: 'static, R: TypeMapSet> TypeMapSet for &mut Ty<V, R>[src]

impl<V: 'static, R: TypeMapSet> TypeMapSet for Ty<V, R>[src]

Loading content...