Trait TryFutureExt
pub trait TryFutureExt: TryFuture
Adapters specific to Result-returning futures
Provided Methods
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok> where Self::Ok: Sink<Item, Error = Self::Error>, Self: Sized,Flattens the execution of this future when the successful result of this future is a
Sink.This can be useful when sink initialization is deferred, and it is convenient to work with that sink as if the sink was available at the call site.
Note that this function consumes this future and returns a wrapped version of it.
Examples
use ; use Sink; # use ; # type T = i32; # type E = SendError; let fut = make_sink_async; take_sinkfn map_ok<T, F>(self, f: F) -> MapOk<Self, F> where F: FnOnce(Self::Ok) -> T, Self: Sized,Maps this future's success value to a different value.
This method can be used to change the
Oktype of the future into a different type. It is similar to theResult::mapmethod. You can use this method to chain along a computation once the future has been resolved.The provided closure
fwill only be called if this future is resolved to anOk. If it resolves to anErr, panics, or is dropped, then the provided closure will never be invoked.Note that this method consumes the future it is called on and returns a wrapped version of it.
Examples
use TryFutureExt; # block_on;Calling
map_okon an errored future has no effect:use TryFutureExt; # block_on;fn map_ok_or_else<T, E, F>(self, e: E, f: F) -> MapOkOrElse<Self, F, E> where F: FnOnce(Self::Ok) -> T, E: FnOnce(Self::Error) -> T, Self: Sized,Maps this future's success value to a different value, and permits for error handling resulting in the same type.
This method can be used to coalesce your
Oktype andErrorinto another type, where that type is the same for both outcomes.The provided closure
fwill only be called if this future is resolved to anOk. If it resolves to anErr, panics, or is dropped, then the provided closure will never be invoked.The provided closure
ewill only be called if this future is resolved to anErr. If it resolves to anOk, panics, or is dropped, then the provided closure will never be invoked.Note that this method consumes the future it is called on and returns a wrapped version of it.
Examples
use TryFutureExt; # block_on;fn map_err<E, F>(self, f: F) -> MapErr<Self, F> where F: FnOnce(Self::Error) -> E, Self: Sized,Maps this future's error value to a different value.
This method can be used to change the
Errortype of the future into a different type. It is similar to theResult::map_errmethod. You can use this method for example to ensure that futures have the sameErrortype when usingselect!orjoin!.The provided closure
fwill only be called if this future is resolved to anErr. If it resolves to anOk, panics, or is dropped, then the provided closure will never be invoked.Note that this method consumes the future it is called on and returns a wrapped version of it.
Examples
use TryFutureExt; # block_on;Calling
map_erron a successful future has no effect:use TryFutureExt; # block_on;fn err_into<E>(self) -> ErrInto<Self, E> where Self: Sized, Self::Error: Into<E>,Maps this future's
Errorto a new error type using theIntotrait.This method does for futures what the
?-operator does for [Result]: It lets the compiler infer the type of the resulting error. Just asmap_err, this is useful for example to ensure that futures have the sameErrortype when usingselect!orjoin!.Note that this method consumes the future it is called on and returns a wrapped version of it.
Examples
use TryFutureExt; # block_on;fn ok_into<U>(self) -> OkInto<Self, U> where Self: Sized, Self::Ok: Into<U>,fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F> where F: FnOnce(Self::Ok) -> Fut, Fut: TryFuture<Error = Self::Error>, Self: Sized,Executes another future after this one resolves successfully. The success value is passed to a closure to create this subsequent future.
The provided closure
fwill only be called if this future is resolved to anOk. If this future resolves to anErr, panics, or is dropped, then the provided closure will never be invoked. TheErrortype of this future and the future returned byfhave to match.Note that this method consumes the future it is called on and returns a wrapped version of it.
Examples
use TryFutureExt; # block_on;Calling
and_thenon an errored future has no effect:use TryFutureExt; # block_on;fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F> where F: FnOnce(Self::Error) -> Fut, Fut: TryFuture<Ok = Self::Ok>, Self: Sized,Executes another future if this one resolves to an error. The error value is passed to a closure to create this subsequent future.
The provided closure
fwill only be called if this future is resolved to anErr. If this future resolves to anOk, panics, or is dropped, then the provided closure will never be invoked. TheOktype of this future and the future returned byfhave to match.Note that this method consumes the future it is called on and returns a wrapped version of it.
Examples
use TryFutureExt; # block_on;Calling
or_elseon a successful future has no effect:use TryFutureExt; # block_on;fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F> where F: FnOnce(&Self::Ok), Self: Sized,Do something with the success value of a future before passing it on.
When using futures, you'll often chain several of them together. While working on such code, you might want to check out what's happening at various parts in the pipeline, without consuming the intermediate value. To do that, insert a call to
inspect_ok.Examples
# block_on;fn inspect_err<F>(self, f: F) -> InspectErr<Self, F> where F: FnOnce(&Self::Error), Self: Sized,Do something with the error value of a future before passing it on.
When using futures, you'll often chain several of them together. While working on such code, you might want to check out what's happening at various parts in the pipeline, without consuming the intermediate value. To do that, insert a call to
inspect_err.Examples
# block_on;fn try_flatten(self) -> TryFlatten<Self, Self::Ok> where Self::Ok: TryFuture<Error = Self::Error>, Self: Sized,Flatten the execution of this future when the successful result of this future is another future.
This is equivalent to
future.and_then(|x| x).fn try_flatten_stream(self) -> TryFlattenStream<Self> where Self::Ok: TryStream<Error = Self::Error>, Self: Sized,Flatten the execution of this future when the successful result of this future is a stream.
This can be useful when stream initialization is deferred, and it is convenient to work with that stream as if stream was available at the call site.
Note that this function consumes this future and returns a wrapped version of it.
Examples
# block_on;fn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> where Self: Sized, F: FnOnce(Self::Error) -> Self::Ok,Unwraps this future's output, producing a future with this future's
Oktype as itsOutputtype.If this future is resolved successfully, the returned future will contain the original future's success value as output. Otherwise, the closure
fis called with the error value to produce an alternate success value.This method is similar to the
Result::unwrap_or_elsemethod.Examples
use TryFutureExt; # block_on;fn into_future(self) -> IntoFuture<Self> where Self: Sized,Wraps a
TryFutureinto a type that implementsFuture.TryFutures currently do not implement theFuturetrait due to limitations of the compiler.Examples
use ; # type T = i32; # type E = ; take_future;fn try_poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<Self::Ok, Self::Error>> where Self: Unpin,A convenience method for calling
TryFuture::try_pollonUnpinfuture types.
Implementors
impl<Fut> TryFutureExt for Abortable<T> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for AlwaysReady<T, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for AndThen<Fut1, Fut2, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for CatchUnwind<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Close<'a, Si, Item> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Close<'a, W> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Concat<St> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Copy<'a, R, W> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for CopyBuf<'a, R, W> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for CopyBufAbortable<'a, R, W> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Either<A, B> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for ErrInto<Fut, E> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Feed<'a, Si, Item> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for FillBuf<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Flatten<F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Flush<'a, Si, Item> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Flush<'a, W> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Fold<St, Fut, T, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Forward<St, Si> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Fuse<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Inspect<Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for InspectErr<Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for InspectOk<Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for IntoFuture<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Lazy<F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Map<Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for MapErr<Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for MapInto<Fut, T> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for MapOk<Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for MapOkOrElse<Fut, F, G> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for NeverError<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for OkInto<Fut, E> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for OrElse<Fut1, Fut2, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Pending<T> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for PollFn<F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Read<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for ReadExact<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for ReadLine<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for ReadToEnd<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for ReadToString<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for ReadUntil<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for ReadVectored<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Ready<T> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for RemoteHandle<T> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for SeeKRelative<'a, R> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Seek<'a, S> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for SelectNextSome<'a, St> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for SelectOk<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Send<'a, Si, Item> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for SendAll<'a, Si, St> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Shared<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Then<Fut1, Fut2, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryAll<St, Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryAny<St, Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryCollect<St, C> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryConcat<St> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryFlatten<Fut1, Fut2> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryFold<St, Fut, T, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryForEach<St, Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryForEachConcurrent<St, Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryJoin<Fut1, Fut2> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryJoin3<Fut1, Fut2, Fut3> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryJoin4<Fut1, Fut2, Fut3, Fut4> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryJoin5<Fut1, Fut2, Fut3, Fut4, Fut5> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryJoinAll<F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryMaybeDone<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TryNext<'a, St> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for TrySelect<A, B> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for UnitError<Fut> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for UnwrapOrElse<Fut, F> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for Write<'a, W> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for WriteAll<'a, W> where Fut: TryFuture + ?Sized,impl<Fut> TryFutureExt for WriteVectored<'a, W> where Fut: TryFuture + ?Sized,impl<Fut: ?Sized + TryFuture> TryFutureExt for Fut