pub struct AsyncOption<T: 'static> { /* private fields */ }Implementations§
Source§impl<T> AsyncOption<T>
impl<T> AsyncOption<T>
Sourcepub fn new(value: Option<T>) -> AsyncOption<T> ⓘ
pub fn new(value: Option<T>) -> AsyncOption<T> ⓘ
Create a new asynchronous option.
§Examples
use tokio::runtime::Runtime;
let runtime = Runtime::new().unwrap();
let result = runtime.block_on(async {
let res: AsyncOption<u8> = AsyncOption::new(Some(1));
res.await
});
println!("{:?}", result);Sourcepub fn raw<V: Future<Output = Option<T>> + 'static>(value: V) -> AsyncOption<T> ⓘ
pub fn raw<V: Future<Output = Option<T>> + 'static>(value: V) -> AsyncOption<T> ⓘ
Create a new asynchronous option from a raw future.
§Examples
use tokio::runtime::Runtime;
let runtime = Runtime::new().unwrap();
let result = runtime.block_on(async {
let res: AsyncOption<u8> = AsyncOption::raw(async { Some(1) });
res.await
});
println!("{:?}", result);pub fn and<U>( self, optb: impl Future<Output = Option<U>> + 'static, ) -> AsyncOption<U> ⓘ
pub fn and_then<F, V>(self, f: impl FnOnce(T) -> F + 'static) -> AsyncOption<V> ⓘ
pub fn or( self, optb: impl Future<Output = Option<T>> + 'static, ) -> AsyncOption<T> ⓘ
pub fn or_else<F>(self, f: impl FnOnce() -> F + 'static) -> AsyncOption<T> ⓘ
pub fn xor( self, optb: impl Future<Output = Option<T>> + 'static, ) -> AsyncOption<T> ⓘ
pub fn ok_or<E: 'static>( self, err: impl Future<Output = E> + 'static, ) -> AsyncResult<T, E> ⓘ
pub fn ok_or_else<E, F>(
self,
f: impl FnOnce() -> F + 'static,
) -> AsyncResult<T, E> ⓘwhere
F: Future<Output = E> + 'static,
E: 'static,
pub fn map<F, V>(self, f: impl FnOnce(T) -> F + 'static) -> AsyncOption<V> ⓘwhere
F: Future<Output = V> + 'static,
V: 'static,
pub fn zip<U>( self, other: impl Future<Output = Option<U>> + 'static, ) -> AsyncOption<(T, U)> ⓘ
pub fn zip_with<U, F, R>(
self,
other: impl Future<Output = Option<U>> + 'static,
f: impl FnOnce(T, U) -> F + 'static,
) -> AsyncOption<R> ⓘwhere
F: Future<Output = R>,
pub fn filter<F>(self, predicate: impl FnOnce(&T) -> F + 'static) -> Self
pub fn inspect<F>(self, f: impl FnOnce(&T) -> F + 'static) -> Self
pub async fn map_or<U, F>(self, default: F, f: impl FnOnce(T) -> F) -> Uwhere
F: Future<Output = U> + 'static,
U: 'static,
pub async fn map_or_else<U, F>(
self,
default: impl FnOnce() -> F,
f: impl FnOnce(T) -> F,
) -> Uwhere
F: Future<Output = U> + 'static,
U: 'static,
pub async fn is_none(self) -> bool
pub async fn is_some(self) -> bool
pub async fn is_some_and<F>(self, f: impl FnOnce(T) -> F) -> bool
pub async fn is_none_or<F>(self, f: impl FnOnce(T) -> F) -> bool
Source§impl<T, E> AsyncOption<AsyncResult<T, E>>
impl<T, E> AsyncOption<AsyncResult<T, E>>
Sourcepub fn transpose(self) -> AsyncResult<Option<T>, E> ⓘ
pub fn transpose(self) -> AsyncResult<Option<T>, E> ⓘ
This operation does not return an AsyncOption because it has to await both
the result and the option, thus creating another AsyncOption is only an
additional burden.
Source§impl<T, E> AsyncOption<Result<T, E>>
impl<T, E> AsyncOption<Result<T, E>>
Sourcepub fn transpose(self) -> AsyncResult<Option<T>, E> ⓘ
pub fn transpose(self) -> AsyncResult<Option<T>, E> ⓘ
This operation does not return an AsyncOption because it has to await
the option, thus creating another AsyncOption is only an additional burden.
Source§impl<T> AsyncOption<AsyncOption<T>>
impl<T> AsyncOption<AsyncOption<T>>
pub fn flatten(self) -> AsyncOption<T> ⓘ
Source§impl<T> AsyncOption<Option<T>>
impl<T> AsyncOption<Option<T>>
pub fn flatten(self) -> AsyncOption<T> ⓘ
Trait Implementations§
Source§impl<T: 'static> From<Option<T>> for AsyncOption<T>
impl<T: 'static> From<Option<T>> for AsyncOption<T>
Source§impl<T> Future for AsyncOption<T>
impl<T> Future for AsyncOption<T>
Auto Trait Implementations§
impl<T> Freeze for AsyncOption<T>
impl<T> !RefUnwindSafe for AsyncOption<T>
impl<T> !Send for AsyncOption<T>
impl<T> !Sync for AsyncOption<T>
impl<T> Unpin for AsyncOption<T>
impl<T> !UnwindSafe for AsyncOption<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more