Trait TryFutureExt
trait TryFutureExt: TryFuture
Adapters specific to Result-returning futures
Provided Methods
fn flatten_sink<Item>(self: Self) -> FlattenSink<Self, <Self as >::Ok> where <Self as >::Ok: Sink<Item, Error = <Self as >::Error>, Self: SizedFlattens 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: Self, f: F) -> MapOk<Self, F> where F: FnOnce(<Self as >::Ok) -> T, Self: SizedMaps 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: Self, e: E, f: F) -> MapOkOrElse<Self, F, E> where F: FnOnce(<Self as >::Ok) -> T, E: FnOnce(<Self as >::Error) -> T, Self: SizedMaps 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: Self, f: F) -> MapErr<Self, F> where F: FnOnce(<Self as >::Error) -> E, Self: SizedMaps 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: Self) -> ErrInto<Self, E> where Self: Sized, <Self as >::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: Self) -> OkInto<Self, U> where Self: Sized, <Self as >::Ok: Into<U>fn and_then<Fut, F>(self: Self, f: F) -> AndThen<Self, Fut, F> where F: FnOnce(<Self as >::Ok) -> Fut, Fut: TryFuture<Error = <Self as >::Error>, Self: SizedExecutes 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: Self, f: F) -> OrElse<Self, Fut, F> where F: FnOnce(<Self as >::Error) -> Fut, Fut: TryFuture<Ok = <Self as >::Ok>, Self: SizedExecutes 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: Self, f: F) -> InspectOk<Self, F> where F: FnOnce(&<Self as >::Ok), Self: SizedDo 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: Self, f: F) -> InspectErr<Self, F> where F: FnOnce(&<Self as >::Error), Self: SizedDo 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: Self) -> TryFlatten<Self, <Self as >::Ok> where <Self as >::Ok: TryFuture<Error = <Self as >::Error>, Self: SizedFlatten 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: Self) -> TryFlattenStream<Self> where <Self as >::Ok: TryStream<Error = <Self as >::Error>, Self: SizedFlatten 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: Self, f: F) -> UnwrapOrElse<Self, F> where Self: Sized, F: FnOnce(<Self as >::Error) -> <Self as >::OkUnwraps 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: Self) -> IntoFuture<Self> where Self: SizedWraps 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(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<<Self as >::Ok, <Self as >::Error>> where Self: UnpinA convenience method for calling
TryFuture::try_pollonUnpinfuture types.
Implementors
impl<Fut> TryFutureExt for Close<'a, Si, Item>impl<Fut> TryFutureExt for TryJoin4<Fut1, Fut2, Fut3, Fut4>impl<Fut> TryFutureExt for TryAny<St, Fut, F>impl<Fut> TryFutureExt for Abortable<T>impl<Fut> TryFutureExt for WriteVectored<'a, W>impl<Fut> TryFutureExt for Lazy<F>impl<Fut> TryFutureExt for MapOk<Fut, F>impl<Fut> TryFutureExt for NeverError<Fut>impl<Fut> TryFutureExt for TryAll<St, Fut, F>impl<Fut> TryFutureExt for TryForEach<St, Fut, F>impl<Fut> TryFutureExt for Forward<St, Si>impl<Fut> TryFutureExt for ReadToEnd<'a, R>impl<Fut> TryFutureExt for Concat<St>impl<Fut> TryFutureExt for Write<'a, W>impl<Fut> TryFutureExt for Flush<'a, Si, Item>impl<Fut> TryFutureExt for SelectNextSome<'a, St>impl<Fut> TryFutureExt for Flush<'a, W>impl<Fut> TryFutureExt for Feed<'a, Si, Item>impl<Fut> TryFutureExt for TrySelect<A, B>impl<Fut> TryFutureExt for TryFlatten<Fut1, Fut2>impl<Fut> TryFutureExt for PollFn<F>impl<Fut> TryFutureExt for Send<'a, Si, Item>impl<Fut> TryFutureExt for ReadToString<'a, R>impl<Fut> TryFutureExt for OkInto<Fut, E>impl<Fut> TryFutureExt for MapInto<Fut, T>impl<Fut> TryFutureExt for TryJoinAll<F>impl<Fut> TryFutureExt for Either<A, B>impl<Fut> TryFutureExt for TryNext<'a, St>impl<Fut> TryFutureExt for TryJoin<Fut1, Fut2>impl<Fut> TryFutureExt for Close<'a, W>impl<Fut> TryFutureExt for ReadLine<'a, R>impl<Fut> TryFutureExt for TryForEachConcurrent<St, Fut, F>impl<Fut> TryFutureExt for ReadUntil<'a, R>impl<Fut> TryFutureExt for Shared<Fut>impl<Fut> TryFutureExt for Then<Fut1, Fut2, F>impl<Fut> TryFutureExt for UnwrapOrElse<Fut, F>impl<Fut> TryFutureExt for AndThen<Fut1, Fut2, F>impl<Fut> TryFutureExt for AlwaysReady<T, F>impl<Fut> TryFutureExt for FillBuf<'a, R>impl<Fut> TryFutureExt for RemoteHandle<T>impl<Fut> TryFutureExt for SelectOk<Fut>impl<Fut> TryFutureExt for SeeKRelative<'a, R>impl<Fut> TryFutureExt for TryConcat<St>impl<Fut> TryFutureExt for CopyBufAbortable<'a, R, W>impl<Fut> TryFutureExt for Pending<T>impl<Fut> TryFutureExt for MapErr<Fut, F>impl<Fut> TryFutureExt for OrElse<Fut1, Fut2, F>impl<Fut> TryFutureExt for Map<Fut, F>impl<Fut> TryFutureExt for IntoFuture<Fut>impl<Fut> TryFutureExt for ReadExact<'a, R>impl<Fut> TryFutureExt for Flatten<F>impl<Fut> TryFutureExt for Copy<'a, R, W>impl<Fut> TryFutureExt for Ready<T>impl<Fut> TryFutureExt for ReadVectored<'a, R>impl<Fut> TryFutureExt for MapOkOrElse<Fut, F, G>impl<Fut> TryFutureExt for TryFold<St, Fut, T, F>impl<Fut> TryFutureExt for ErrInto<Fut, E>impl<Fut> TryFutureExt for TryJoin5<Fut1, Fut2, Fut3, Fut4, Fut5>impl<Fut> TryFutureExt for SendAll<'a, Si, St>impl<Fut> TryFutureExt for Read<'a, R>impl<Fut> TryFutureExt for InspectOk<Fut, F>impl<Fut: ?Sized + TryFuture> TryFutureExt for Futimpl<Fut> TryFutureExt for UnitError<Fut>impl<Fut> TryFutureExt for Fuse<Fut>impl<Fut> TryFutureExt for TryCollect<St, C>impl<Fut> TryFutureExt for Seek<'a, S>impl<Fut> TryFutureExt for CopyBuf<'a, R, W>impl<Fut> TryFutureExt for TryJoin3<Fut1, Fut2, Fut3>impl<Fut> TryFutureExt for TryMaybeDone<Fut>impl<Fut> TryFutureExt for InspectErr<Fut, F>impl<Fut> TryFutureExt for Fold<St, Fut, T, F>impl<Fut> TryFutureExt for Inspect<Fut, F>impl<Fut> TryFutureExt for CatchUnwind<Fut>impl<Fut> TryFutureExt for WriteAll<'a, W>