Struct illicit::Layer[][src]

pub struct Layer { /* fields omitted */ }
Expand description

A container for the local environment, usually used to represent a pending addition to it.

The environment is type-indexed, and access is provided through read-only references. Call Layer::offer to include new values in the environment for called functions and get or expect to retrieve references to the offered values.

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.

Examples

Code always sees the contents of the “bottom-most” Layer:

illicit::Layer::new().offer(String::new()).offer(5u16).enter(|| {
    assert!(illicit::expect::<String>().is_empty());
    assert_eq!(*illicit::expect::<u16>(), 5);

    illicit::Layer::new().offer(10u16).enter(|| {
        assert!(illicit::expect::<String>().is_empty());
        assert_eq!(*illicit::expect::<u16>(), 10);
    });

    assert!(illicit::expect::<String>().is_empty());
    assert_eq!(*illicit::expect::<u16>(), 5);
});

Implementations

Construct a new layer which defaults to the contents of the current one. Call Layer::offer to add values to the new layer before calling Layer::enter to run a closure with access to the new and old values.

Adds the new item and returns the modified layer.

The offered type must implement Debug to allow get’s errors to display the contents of the illicit environment. It must also satisfy the 'static lifetime because get is unable to express any lifetime constraints at its callsite.

Call child_fn with this layer as the local environment.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Call op within the context of a Layer containing self.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.