Skip to main content

ExtExt

Trait ExtExt 

Source
pub trait ExtExt<T>
where Self: Future<Output = T> + Send,
{ // Required methods fn until<A, B, F>(self, f: F) -> Select<A, B> ⓘ where Self: Sized, F: FnOnce() -> B, A: Future<Output = T> + From<Self> + Send + Unpin, B: Future<Output = ()> + Send + Unpin; fn timed(self) -> impl Future<Output = (T, Duration)> + Send where Self: Sized; }
Expand description

Adds a stop-future race and a completion timer to ordinary futures.

until hands back a selector over the receiver and a stopping future; timed hands back the receiver’s output with how long it took.

Required Methods§

Source

fn until<A, B, F>(self, f: F) -> Select<A, B> ⓘ
where Self: Sized, F: FnOnce() -> B, A: Future<Output = T> + From<Self> + Send + Unpin, B: Future<Output = ()> + Send + Unpin,

Races the receiver against a unit-output stopping future.

f constructs the stopping future when the selector is created. The returned [Select] preserves whichever future has not completed.

Source

fn timed(self) -> impl Future<Output = (T, Duration)> + Send
where Self: Sized,

Resolves to the receiver’s output and how long it took.

The clock starts when the returned future is first polled, so time spent before it is awaited does not count.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, Fut> ExtExt<T> for Fut
where Fut: Future<Output = T> + Send,