Struct WhenProvider

Source
pub struct WhenProvider<L, P, Cx, Out> { /* private fields */ }
Expand description

Return type of when_provider().

§Example

use dynamic_provider::{when_provider, ProvideRef};

dynamic_provider::define_tag! {
    tag Details: for<'x> (&'x str, &'x str);
}

fn get_details(provider: &dyn ProvideRef) -> String {
    when_provider(provider)
        .has_value::<String>(|s| s)
        .has_ref::<str>(|s| s.into())
        .has::<Details>((), |(a, b)| format!("{a}, {b}"))
        .or_else(|_| "unknown".into())
}

Implementations§

Source§

impl<L: Lt, P: Provide<L>, Out> WhenProvider<L, P, NoContext, Out>

Source

pub fn finish(self) -> Result<Out, P>

Returns the output of the successful request if there is one, or an Err containing the original provider.

Source

pub fn or_else(self, f: impl FnOnce(P) -> Out) -> Out

Returns the output of the successful request if there is one, or the return value of the given function that accepts the original provider.

Source

pub fn with<Cx>(self, context: Cx) -> WhenProvider<L, P, HasContext<Cx>, Out>

Adds a context value to all subsequent request handlers, which will be passed as the second callback parameter.

Source

pub fn has<Tag: TagFor<L>>( self, arg: Tag::ArgValue, transform: impl FnOnce(Tag::Value) -> Out, ) -> Self

Handle the case where the type marked by Tag is supplied by the provider.

Source

pub fn has_value<T: 'static>(self, transform: impl FnOnce(T) -> Out) -> Self

Handle the case where a value of type T, marked by Value<T>, is supplied by the provider.

Source§

impl<'x, L: Lt, P: Provide<LtList<'x, L>>, Out> WhenProvider<LtList<'x, L>, P, NoContext, Out>

Source

pub fn has_ref<T: 'static + ?Sized>( self, transform: impl FnOnce(&'x T) -> Out, ) -> Self

Handle the case where a shared reference to a value of type T, marked by Ref<Value<T>>, is supplied by the provider.

Source

pub fn has_mut<T: 'static + ?Sized>( self, transform: impl FnOnce(&'x mut T) -> Out, ) -> Self

Handle the case where a unique reference to a value of type T, marked by Mut<Value<T>>, is supplied by the provider.

Source§

impl<L: Lt, P: Provide<L>, Cx, Out> WhenProvider<L, P, HasContext<Cx>, Out>

Source

pub fn finish(self) -> Result<Out, (P, Cx)>

Returns the output of the successful request if there is one, or an Err containing the original provider and the context value.

Source

pub fn or_else(self, f: impl FnOnce(P, Cx) -> Out) -> Out

Returns the output of the successful request if there is one, or the return value of the given function that accepts the original provider and the context value.

Source

pub fn has<Tag: TagFor<L>>( self, arg: Tag::ArgValue, transform: impl FnOnce(Tag::Value, Cx) -> Out, ) -> Self

Handle the case where the type marked by Tag is supplied by the provider.

Source

pub fn has_value<T: 'static>(self, transform: impl FnOnce(T, Cx) -> Out) -> Self

Handle the case where a value of type T, marked by Value<T>, is supplied by the provider.

Source§

impl<'x, L: Lt, P: Provide<LtList<'x, L>>, Cx, Out> WhenProvider<LtList<'x, L>, P, HasContext<Cx>, Out>

Source

pub fn has_ref<T: 'static + ?Sized>( self, transform: impl FnOnce(&'x T, Cx) -> Out, ) -> Self

Handle the case where a shared reference to a value of type T, marked by Ref<Value<T>>, is supplied by the provider.

Source

pub fn has_mut<T: 'static + ?Sized>( self, transform: impl FnOnce(&'x mut T, Cx) -> Out, ) -> Self

Handle the case where a unique reference to a value of type T, marked by Mut<Value<T>>, is supplied by the provider.

Auto Trait Implementations§

§

impl<L, P, Cx, Out> Freeze for WhenProvider<L, P, Cx, Out>
where P: Freeze, Cx: Freeze, Out: Freeze,

§

impl<L, P, Cx, Out> RefUnwindSafe for WhenProvider<L, P, Cx, Out>

§

impl<L, P, Cx, Out> Send for WhenProvider<L, P, Cx, Out>
where P: Send, Cx: Send, Out: Send, L: Send,

§

impl<L, P, Cx, Out> Sync for WhenProvider<L, P, Cx, Out>
where P: Sync, Cx: Sync, Out: Sync, L: Sync,

§

impl<L, P, Cx, Out> Unpin for WhenProvider<L, P, Cx, Out>
where P: Unpin, Cx: Unpin, Out: Unpin, L: Unpin,

§

impl<L, P, Cx, Out> UnwindSafe for WhenProvider<L, P, Cx, Out>
where P: UnwindSafe, Cx: UnwindSafe, Out: UnwindSafe, L: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.