Trait typemap_core::TypeMapGet [−][src]
The TypeMapGet trait allows for obtaining values of types from a typemap.
Required methods
fn try_get<T: 'static>(&self) -> Option<&T>
[src]
Attempts to obtain a value of a given type from 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 None
if the type is not present in the map.
On nightly, this should only occur if Contains<T>
is not implemented.
use typemap_core::{typemap, TypeMapGet}; let map = typemap!(u32 = 23u32); assert_eq!(map.try_get::<u32>(), Some(&23u32)); assert_eq!(map.try_get::<u128>(), None);
Provided methods
fn get<T: 'static>(&self) -> &T where
Self: Contains<T>,
[src]
Self: Contains<T>,
Obtains a value of a given type from the map.
On nightly, you can only call this method if the type is actually present.
(i.e. the map implements implements Contains<T>
)
Panics
This function panics if try_get
would return None
.
This should only be possible on stable,
so you can weed out potential panics by occasionally checking against nightly.
use typemap_core::{typemap, TypeMapGet}; let map = typemap!(u32 = 23u32, &str = "Hello, world!"); println!("{}", map.get::<&str>());