pub trait AsyncOptionExt<T> {
// Required method
async fn async_map<U, Fut: Future<Output = U>, F: FnOnce(T) -> Fut>(
self,
f: F,
) -> Option<U>;
}
Required Methods§
Sourceasync fn async_map<U, Fut: Future<Output = U>, F: FnOnce(T) -> Fut>(
self,
f: F,
) -> Option<U>
async fn async_map<U, Fut: Future<Output = U>, F: FnOnce(T) -> Fut>( self, f: F, ) -> Option<U>
Maps an Option<T>
to Option<U>
by applying a function to a contained value (if Some
) or returns None
(if None
).
§Example
use composable_utils::AsyncOptionExt;
async fn double(x: usize) -> usize {
x * 2
}
async_io::block_on(async {
let value = Some(69);
let value = value
.async_map(|v| async move { double(v).await })
.await
.unwrap_or_else(|| panic!("value should always be Some"));
assert_eq!(value, 138);
});
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.