pub trait FutureExt: Future + Sized {
// Provided methods
fn into_boxed(self) -> BoxFuture<Self::Item, Self::Error>
where Self: 'static { ... }
fn into_send_boxed(self) -> BoxSendFuture<Self::Item, Self::Error>
where Self: Send + 'static { ... }
fn until<C>(self, condition: C) -> Until<Self, C>
where C: Future<Item = ()>,
Self::Error: From<C::Error> { ... }
fn infallible<E>(self) -> Infallible<Self, E>
where Self: Future<Error = Void> { ... }
fn log_error(
self,
level: LogLevel,
description: &'static str,
) -> LogError<Self>
where Self: Future<Item = ()>,
Self::Error: Display { ... }
fn finally<D>(self, on_drop: D) -> Finally<Self, D>
where D: FnOnce() { ... }
fn with_timeout(self, duration: Duration) -> WithTimeout<Self> { ... }
fn with_timeout_at(self, instant: Instant) -> WithTimeout<Self> { ... }
fn first_ok2<F>(self, other: F) -> FirstOk2<Self, F>
where F: Future<Item = Self::Item> { ... }
fn while_driving<F: Future>(self, other: F) -> WhileDriving<Self, F> { ... }
fn resume_unwind(self) -> ResumeUnwind<Self>
where Self: Future<Error = Box<dyn Any + Send + 'static>> { ... }
}
Expand description
Extension trait for Future
.
Provided Methods§
Sourcefn into_boxed(self) -> BoxFuture<Self::Item, Self::Error>where
Self: 'static,
fn into_boxed(self) -> BoxFuture<Self::Item, Self::Error>where
Self: 'static,
Wraps a future into a boxed future, making type-checking easier at the expense of an extra layer of indirection at runtime.
fn into_send_boxed(self) -> BoxSendFuture<Self::Item, Self::Error>where
Self: Send + 'static,
Sourcefn until<C>(self, condition: C) -> Until<Self, C>
fn until<C>(self, condition: C) -> Until<Self, C>
Run this future until some condition is met. If condition
resolves before self
then
None
is returned.
§Example
let my_future_with_timeout = my_future.until(Delay::new(Instant::now() + Duration::from_secs(1)));
Sourcefn infallible<E>(self) -> Infallible<Self, E>
fn infallible<E>(self) -> Infallible<Self, E>
For futures which can’t fail (ie. which have error type Void
), cast the error type to
some inferred type.
Sourcefn log_error(self, level: LogLevel, description: &'static str) -> LogError<Self>
fn log_error(self, level: LogLevel, description: &'static str) -> LogError<Self>
Take a future which returns ()
and log its error if it fails. The returned future cannot
fail and will always resolve to ()
.
Sourcefn finally<D>(self, on_drop: D) -> Finally<Self, D>where
D: FnOnce(),
fn finally<D>(self, on_drop: D) -> Finally<Self, D>where
D: FnOnce(),
Executes the future and runs the provided callback when the future finishes. The callback will also be run if the entire future is dropped.
Sourcefn with_timeout(self, duration: Duration) -> WithTimeout<Self>
fn with_timeout(self, duration: Duration) -> WithTimeout<Self>
Runs the future for the given duration, returning its value in an option, or returning
None
if the timeout expires.
Sourcefn with_timeout_at(self, instant: Instant) -> WithTimeout<Self>
fn with_timeout_at(self, instant: Instant) -> WithTimeout<Self>
Runs the future until the given instant, returning its value in an option, or returning
None
if the timeout expires.
Sourcefn first_ok2<F>(self, other: F) -> FirstOk2<Self, F>
fn first_ok2<F>(self, other: F) -> FirstOk2<Self, F>
Run two futures in parallel and yield the value of the first to return success. If both futures fail, return both errors.
Sourcefn while_driving<F: Future>(self, other: F) -> WhileDriving<Self, F>
fn while_driving<F: Future>(self, other: F) -> WhileDriving<Self, F>
Resolves self
while driving other
in parallel.
Sourcefn resume_unwind(self) -> ResumeUnwind<Self>
fn resume_unwind(self) -> ResumeUnwind<Self>
Propogates the result of a .catch_unwind
, panicking if the future resolves to an Err
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.