[−][src]Crate illicit
Type-indexed scoped singletons, propagated through an implicit backing context.
Requiring references from the environment
The from_env
macro provides an attribute for functions that require access to a singleton in
their environment. Here, the contrived function requires a u8
to add one to:
#[illicit::from_env(num: &u8)] fn env_num_plus_one() -> u8 { num + 1 } illicit::child_env!(u8 => 1).enter(|| { assert_eq!(env_num_plus_one(), 2u8); });
This provides convenient sugar for values stored in the current Env
as an alternative to
thread-locals or a manually propagated context object. However this approach incurs a
significant cost in that the following code will panic without the right type having been added
to the environment:
// thread 'main' panicked at 'expected a value from the environment, found none' env_num_plus_one();
See the attribute's documentation for more details, and please consider whether this is appropriate for your use case before taking it on as a dependency.
Macros
child_env | Declare additional environment values to expose to a child topological function's call tree. |
Structs
Env | 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. |
EnvSnapshot | An alternative representation of the current scope's environment, optimized for debug printing. |
Attribute Macros
from_env | Defines required [topo::Env] values for a function. Binds the provided types as if references to them were implicit function arguments. |