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>
impl<L: Lt, P: Provide<L>, Out> WhenProvider<L, P, NoContext, Out>
Sourcepub fn finish(self) -> Result<Out, P>
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.
Sourcepub fn or_else(self, f: impl FnOnce(P) -> Out) -> Out
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.
Sourcepub fn with<Cx>(self, context: Cx) -> WhenProvider<L, P, HasContext<Cx>, Out>
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§impl<'x, L: Lt, P: Provide<LtList<'x, L>>, Out> WhenProvider<LtList<'x, L>, P, NoContext, Out>
impl<'x, L: Lt, P: Provide<LtList<'x, L>>, Out> WhenProvider<LtList<'x, L>, P, NoContext, Out>
Source§impl<L: Lt, P: Provide<L>, Cx, Out> WhenProvider<L, P, HasContext<Cx>, Out>
impl<L: Lt, P: Provide<L>, Cx, Out> WhenProvider<L, P, HasContext<Cx>, Out>
Sourcepub fn finish(self) -> Result<Out, (P, Cx)>
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.
Sourcepub fn or_else(self, f: impl FnOnce(P, Cx) -> Out) -> Out
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§impl<'x, L: Lt, P: Provide<LtList<'x, L>>, Cx, Out> WhenProvider<LtList<'x, L>, P, HasContext<Cx>, Out>
impl<'x, L: Lt, P: Provide<LtList<'x, L>>, Cx, Out> WhenProvider<LtList<'x, L>, P, HasContext<Cx>, Out>
Auto Trait Implementations§
impl<L, P, Cx, Out> Freeze for WhenProvider<L, P, Cx, Out>
impl<L, P, Cx, Out> RefUnwindSafe for WhenProvider<L, P, Cx, Out>
impl<L, P, Cx, Out> Send for WhenProvider<L, P, Cx, Out>
impl<L, P, Cx, Out> Sync for WhenProvider<L, P, Cx, Out>
impl<L, P, Cx, Out> Unpin for WhenProvider<L, P, Cx, Out>
impl<L, P, Cx, Out> UnwindSafe for WhenProvider<L, P, Cx, Out>
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