#[provides]Expand description
Annotates an impl block containing a function that provides an instance of a certain type
§Static inject (default)
#[provides] or #[provides(static_inject)] on an impl of type T provides instances of type T, without any specialities.
#[provides]
impl ProvidedStatic {
pub fn new(inner: usize) -> Self {
Self {
inner
}
}
}§Scoped inject
#[provides(scoped_inject)] on an impl of type T provides instances of type Rc<RefCell<T>>.
The provided instance will be a reference-counted pointer (Rc) that is shared in the outer scope, i.e., pointers provided by an individual scoped binding will point to the same instance.
#[provides(scoped_inject)]
impl ProvidedScoped {
pub fn new(inner: usize) -> Self {
Self {
inner
}
}
}§Singleton inject
#[provides(singleton_inject)] on an impl of type T provides instances of type Arc<RwLock<T>>.
The provided instance will be an atomically reference-counted pointer (Arc) that is shared globally, i.e., pointers provided by any singleton binding will point to the same instance.
Functions providing a singleton instance cannot depend on any arguments.
#[provides(singleton_inject)]
impl ProvidedSingleton {
pub fn new() -> Self {
Self { }
}
}