Trait runtime_injector::IntoSingleton [−][src]
pub trait IntoSingleton<D, R, F> where
R: Service,
F: ServiceFactory<D, Result = R>, { #[must_use] fn singleton(self) -> SingletonProvider<D, R, F>; }
Expand description
Defines a conversion into a singleton provider. This trait is automatically implemented for all service factories.
Required methods
#[must_use]fn singleton(self) -> SingletonProvider<D, R, F>
[src]
#[must_use]
fn singleton(self) -> SingletonProvider<D, R, F>Expand description
Creates a singleton provider. Singleton providers create their values only once (when first requested) and reuse that value for each future request.
Example
use runtime_injector::{Injector, IntoSingleton, Svc}; #[derive(Default)] struct Foo; let mut builder = Injector::builder(); builder.provide(Foo::default.singleton()); let injector = builder.build(); let foo1: Svc<Foo> = injector.get().unwrap(); let foo2: Svc<Foo> = injector.get().unwrap(); assert!(Svc::ptr_eq(&foo1, &foo2));
Implementors
impl<D, R, F> IntoSingleton<D, R, F> for F where
R: Service,
F: ServiceFactory<D, Result = R>,
[src]
impl<D, R, F> IntoSingleton<D, R, F> for F where
R: Service,
F: ServiceFactory<D, Result = R>,
[src]