Skip to main content

get

Function get 

Source
pub fn get<E>() -> Result<impl Deref<Target = E> + Debug + 'static, GetFailed>
where E: Any + Debug + 'static,
Expand description

Returns a reference to a value in the current environment if it is present.

§Errors

Returns an error if the requested type is not available in the local environment.

§Examples

let msg = "hello!";
illicit::Layer::new().offer(String::from(msg)).enter(|| {
    assert_eq!(&*illicit::get::<String>().unwrap(), msg);
});

Returns GetFailed if the requested type is not in the environment:

assert!(illicit::get::<String>().is_err());