Trait runtime_injector::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]

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());
Loading content...

Implementors

impl<P> WithCondition for P where
    P: TypedProvider
[src]

fn with_condition<F>(self, condition: F) -> ConditionalProvider<Self, F> where
    F: Service + Fn(&Injector, &RequestInfo) -> bool
[src]

Loading content...