Skip to main content

OptionExt

Trait OptionExt 

Source
pub trait OptionExt<T> {
    // Required method
    fn map_async<F, Fut, U>(self, f: F) -> OptionFuture<Fut> 
       where F: FnOnce(T) -> Fut,
             Fut: Future<Output = U> + Send,
             U: Send;

    // Provided method
    fn map_stream<F, Fut, U>(self, f: F) -> impl Stream<Item = U> + Send
       where F: FnOnce(T) -> Fut,
             Fut: Future<Output = U> + Send,
             U: Send,
             Self: Sized { ... }
}
Expand description

Extends Option with asynchronous mapping adapters.

OptionExt::map_async preserves optionality through future completion. OptionExt::map_stream exposes the mapped result as a zero-or-one stream.

Required Methods§

Source

fn map_async<F, Fut, U>(self, f: F) -> OptionFuture<Fut>
where F: FnOnce(T) -> Fut, Fut: Future<Output = U> + Send, U: Send,

Maps the contained value to a future without eagerly awaiting it.

A Some value yields an [OptionFuture] that resolves to the mapped output. None resolves to None and never calls the mapping closure.

Provided Methods§

Source

fn map_stream<F, Fut, U>(self, f: F) -> impl Stream<Item = U> + Send
where F: FnOnce(T) -> Fut, Fut: Future<Output = U> + Send, U: Send, Self: Sized,

Maps the contained value to a future-backed stream with at most one item.

A Some value yields the mapped output after its future completes. None yields an empty stream and never calls the mapping closure.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T> OptionExt<T> for Option<T>

Source§

fn map_async<F, Fut, U>(self, f: F) -> OptionFuture<Fut>
where F: FnOnce(T) -> Fut, Fut: Future<Output = U> + Send, U: Send,

Implementors§