[][src]Struct illicit::Env

pub struct Env { /* fields omitted */ }

Immutable environment container for the current scope. Environment values can be provided by parent environments, but child functions can only mutate their environment through interior mutability.

The environment is type-indexed, and each Scope holds 0-1 references to every [std::any::Any] + 'static type. Access is provided through read-only references.

Aside: one interesting implication of the above is the ability to define "private scoped global values" which are private to functions which are nonetheless propagating the values with their control flow. This can be useful for runtimes to offer themselves execution-local values in functions which are invoked by external code. It can also be severely abused, like any implicit state, and should be used with caution.

Implementations

impl Env[src]

pub fn depth(&self) -> u32[src]

The number of parent environments from which this environment descends.

pub fn enter<R>(self, child_fn: impl FnOnce() -> R) -> R[src]

Call child_fn with this environment as the current scope.

pub fn get<E>() -> Option<impl Deref<Target = E> + 'static> where
    E: Any + 'static, 
[src]

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

pub fn expect<E>() -> impl Deref<Target = E> + 'static where
    E: Any + 'static, 
[src]

Returns a reference to a value in the current environment, as Env::get does, but panics if the value has not been set in the environment.

pub fn snapshot() -> EnvSnapshot[src]

Returns a snapshot of the current dynamic scope. Most useful for debugging the contained Env.

pub fn hide<E: 'static>()[src]

Removes the provided type from the current environment for the remainder of its scope. Parent environments may still possess a reference to the value.

Trait Implementations

impl Clone for Env[src]

impl Debug for Env[src]

impl Eq for Env[src]

impl PartialEq<Env> for Env[src]

impl StructuralEq for Env[src]

impl StructuralPartialEq for Env[src]

Auto Trait Implementations

impl !RefUnwindSafe for Env

impl !Send for Env

impl !Sync for Env

impl Unpin for Env

impl !UnwindSafe for Env

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.