pub trait Requires<Capability: ?Sized>: Environment {
// Required method
fn Require(&self) -> Arc<Capability>;
}Expand description
A trait that enables an environment (Self) to provide a specific
capability (Capability).
This is the central mechanism for dependency injection. An ActionEffect
can be generic over an environment TEnvironment as long as it has the
bound TEnvironment: Requires<MyCapability>. The effect can then call
Environment.Require() to receive a shared instance of the service it needs
to perform its operation.
The Capability is typically a trait object, such as
dyn FileSystemReader.
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<TEnvironment: Requires<Capability> + ?Sized, Capability: ?Sized> Requires<Capability> for Arc<TEnvironment>
A blanket implementation that allows an Arc<TEnvironment> to provide a
capability if the inner environment TEnvironment can provide it.
impl<TEnvironment: Requires<Capability> + ?Sized, Capability: ?Sized> Requires<Capability> for Arc<TEnvironment>
A blanket implementation that allows an Arc<TEnvironment> to provide a
capability if the inner environment TEnvironment can provide it.
This is a crucial piece of ergonomics that allows code to call .Require()
directly on a shared Arc<TEnvironment> reference without needing to
dereference it first, simplifying effect implementation logic.