Trait runtime_injector_actix::WithCondition [−][src]
pub trait WithCondition: TypedProvider { #[must_use] fn with_condition<F>(self, condition: F) -> ConditionalProvider<Self, F>
where
F: Service + Fn(&Injector, &RequestInfo) -> bool; }
Expand description
Defines a conversion into a conditional provider. This trait is
automatically implemented for all types that implement TypedProvider
.
Required methods
#[must_use]fn with_condition<F>(self, condition: F) -> ConditionalProvider<Self, F> where
F: Service + Fn(&Injector, &RequestInfo) -> bool,
[src]
#[must_use]
fn with_condition<F>(self, condition: F) -> ConditionalProvider<Self, F> whereF: Service + Fn(&Injector, &RequestInfo) -> bool,
Expand description
Creates a conditional provider. Conditional providers create their values only if their condition is met. If the condition is not met, then the provider is skipped.
Example
use runtime_injector::{Injector, IntoSingleton, Svc, WithCondition}; #[derive(Default)] struct Foo; let mut builder = Injector::builder(); builder.provide(Foo::default.singleton().with_condition(|_, _| false)); let injector = builder.build(); let foo: Option<Svc<Foo>> = injector.get().unwrap(); assert!(foo.is_none());
Implementors
impl<P> WithCondition for P where
P: TypedProvider,
[src]
impl<P> WithCondition for P where
P: TypedProvider,
[src]pub fn with_condition<F>(self, condition: F) -> ConditionalProvider<P, F> where
F: Service + Fn(&Injector, &RequestInfo) -> bool,
[src]
F: Service + Fn(&Injector, &RequestInfo) -> bool,