Skip to main content

WithContext

Struct WithContext 

Source
pub struct WithContext<Fut, E, C> { /* private fields */ }
Expand description

Future wrapper produced by .with_context() to add error context.

Wraps the original future, and on error, attaches the context string lazily generated by the stored closure.

Trait Implementations§

Source§

impl<Fut, T, E, C> Future for WithContext<Fut, E, C>
where Fut: Future<Output = Result<T, E>>, E: Error + 'static, C: FnOnce(&E) -> String,

Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Polls the wrapped future, converting any error by adding context.

If the wrapped future resolves to Ok, passes the value through. If Err, applies the context closure, wraps the error (without invoking hooks!).

Source§

type Output = Result<T, AsyncError<E>>

The type of value produced on completion.

Auto Trait Implementations§

§

impl<Fut, E, C> Freeze for WithContext<Fut, E, C>
where Fut: Freeze, C: Freeze,

§

impl<Fut, E, C> RefUnwindSafe for WithContext<Fut, E, C>

§

impl<Fut, E, C> Send for WithContext<Fut, E, C>
where Fut: Send, C: Send, E: Send,

§

impl<Fut, E, C> Sync for WithContext<Fut, E, C>
where Fut: Sync, C: Sync, E: Sync,

§

impl<Fut, E, C> Unpin for WithContext<Fut, E, C>
where Fut: Unpin, C: Unpin, E: Unpin,

§

impl<Fut, E, C> UnsafeUnpin for WithContext<Fut, E, C>
where Fut: UnsafeUnpin, C: UnsafeUnpin,

§

impl<Fut, E, C> UnwindSafe for WithContext<Fut, E, C>
where Fut: UnwindSafe, C: UnwindSafe, E: 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, E, F> AsyncResultChainExt<T, E> for F
where F: Future<Output = Result<T, E>>,

Source§

fn and_then_async<Fut, F, U>(self, f: F) -> AndThenAsync<Self, Fut, F>
where F: FnOnce(T) -> Fut, Fut: Future<Output = Result<U, E>>,

Chains an asynchronous computation to execute if the previous future resolves to Ok. Read more
Source§

impl<T, E, Fut> AsyncResultExt<T, E> for Fut
where Fut: Future<Output = Result<T, E>>,

Source§

fn with_context<C>(self, ctx: C) -> WithContext<Self, E, C>
where C: FnOnce(&E) -> String,

Adds context to an error produced by this future lazily. 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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
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.