AsyncOption

Struct AsyncOption 

Source
pub struct AsyncOption<T: 'static> { /* private fields */ }

Implementations§

Source§

impl<T> AsyncOption<T>

Source

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);
Source

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);
Source

pub fn and<U>( self, optb: impl Future<Output = Option<U>> + 'static, ) -> AsyncOption<U>

Source

pub fn and_then<F, V>(self, f: impl FnOnce(T) -> F + 'static) -> AsyncOption<V>
where F: Future<Output = Option<V>> + 'static, V: 'static,

Source

pub fn or( self, optb: impl Future<Output = Option<T>> + 'static, ) -> AsyncOption<T>

Source

pub fn or_else<F>(self, f: impl FnOnce() -> F + 'static) -> AsyncOption<T>
where F: Future<Output = Option<T>>,

Source

pub fn xor( self, optb: impl Future<Output = Option<T>> + 'static, ) -> AsyncOption<T>

Source

pub fn ok_or<E: 'static>( self, err: impl Future<Output = E> + 'static, ) -> AsyncResult<T, E>

Source

pub fn ok_or_else<E, F>( self, f: impl FnOnce() -> F + 'static, ) -> AsyncResult<T, E>
where F: Future<Output = E> + 'static, E: 'static,

Source

pub fn map<F, V>(self, f: impl FnOnce(T) -> F + 'static) -> AsyncOption<V>
where F: Future<Output = V> + 'static, V: 'static,

Source

pub fn zip<U>( self, other: impl Future<Output = Option<U>> + 'static, ) -> AsyncOption<(T, U)>

Source

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>,

Source

pub fn filter<F>(self, predicate: impl FnOnce(&T) -> F + 'static) -> Self
where F: Future<Output = bool>,

Source

pub fn inspect<F>(self, f: impl FnOnce(&T) -> F + 'static) -> Self
where F: Future<Output = ()> + 'static,

Source

pub async fn map_or<U, F>(self, default: F, f: impl FnOnce(T) -> F) -> U
where F: Future<Output = U> + 'static, U: 'static,

Source

pub async fn map_or_else<U, F>( self, default: impl FnOnce() -> F, f: impl FnOnce(T) -> F, ) -> U
where F: Future<Output = U> + 'static, U: 'static,

Source

pub async fn is_none(self) -> bool

Source

pub async fn is_some(self) -> bool

Source

pub async fn is_some_and<F>(self, f: impl FnOnce(T) -> F) -> bool
where F: Future<Output = bool>,

Source

pub async fn is_none_or<F>(self, f: impl FnOnce(T) -> F) -> bool
where F: Future<Output = bool>,

Source§

impl<T, E> AsyncOption<AsyncResult<T, E>>

Source

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>>

Source

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>>

Source

pub fn flatten(self) -> AsyncOption<T>

Source§

impl<T> AsyncOption<Option<T>>

Source

pub fn flatten(self) -> AsyncOption<T>

Trait Implementations§

Source§

impl<T: 'static> From<Option<T>> for AsyncOption<T>

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Future for AsyncOption<T>

Source§

type Output = Option<T>

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.