pub struct SingletonProvider<T> { /* private fields */ }
Expand description
Implementations§
Source§impl<T> SingletonProvider<T>
impl<T> SingletonProvider<T>
Sourcepub fn eager_create(self, eager_create: bool) -> Self
pub fn eager_create(self, eager_create: bool) -> Self
Sets whether the provider is eager to create.
Source§impl<T: 'static> SingletonProvider<T>
impl<T: 'static> SingletonProvider<T>
Sourcepub fn bind<U, F>(self, transform: F) -> Self
pub fn bind<U, F>(self, transform: F) -> Self
Create a provider of type Provider<U>
, save it to the current provider.
This method accepts a parameter of fn(T) -> U
, which in combination
with the current provider’s constructor of type fn(&mut Context) -> T
,
creates a Provider<U>
with constructor fn(&mut Context) -> U
and other fields consistent with the current provider.
All bound providers will be registered together
when the current provider is registered in the Context
.
§Example
use std::{fmt::Debug, rc::Rc, sync::Arc};
use rudi::{singleton, Provider, SingletonProvider};
#[derive(Clone, Debug)]
struct A(i32);
fn into_debug(a: A) -> Rc<dyn Debug> {
Rc::new(a)
}
fn main() {
let p: SingletonProvider<A> = singleton(|cx| A(cx.resolve()))
.bind(Rc::new)
.bind(Arc::new)
.bind(Box::new)
.bind(into_debug);
let p: Provider<A> = p.into();
assert_eq!(p.binding_definitions().unwrap().len(), 4);
}
Trait Implementations§
Source§impl<T: 'static + Clone> From<SingletonProvider<T>> for DynProvider
impl<T: 'static + Clone> From<SingletonProvider<T>> for DynProvider
Source§fn from(value: SingletonProvider<T>) -> Self
fn from(value: SingletonProvider<T>) -> Self
Converts to this type from the input type.
Source§impl<T: 'static + Clone> From<SingletonProvider<T>> for Provider<T>
impl<T: 'static + Clone> From<SingletonProvider<T>> for Provider<T>
Source§fn from(value: SingletonProvider<T>) -> Self
fn from(value: SingletonProvider<T>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<T> Freeze for SingletonProvider<T>
impl<T> !RefUnwindSafe for SingletonProvider<T>
impl<T> !Send for SingletonProvider<T>
impl<T> !Sync for SingletonProvider<T>
impl<T> Unpin for SingletonProvider<T>
impl<T> !UnwindSafe for SingletonProvider<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more