pub struct MaybeAsync<T> { /* private fields */ }Expand description
Represents a result that may be computed synchronously or asynchronously by user code.
Rust does not currently allow async fn in trait methods, so we need
a workaround. There are crates such as async_trait which provide proc_macros
that do this, but they don’t provide an optimization to avoid the heap allocation
if the underlying implementation is synchronous.
This allows us to use async operations in Rust if desired, but just have synchronous callbacks
in the FFI without paying always allocating.
Implementations§
Source§impl<T> MaybeAsync<T>
impl<T> MaybeAsync<T>
Sourcepub async fn get(self) -> T
pub async fn get(self) -> T
Retrieve the value, which might be available immediately or require awaiting
Sourcepub fn asynchronous<F>(result: F) -> Self
pub fn asynchronous<F>(result: F) -> Self
Construct a new MaybeAsync from a future which yields the value eventually
Auto Trait Implementations§
impl<T> Freeze for MaybeAsync<T>where
T: Freeze,
impl<T> !RefUnwindSafe for MaybeAsync<T>
impl<T> Send for MaybeAsync<T>where
T: Send,
impl<T> !Sync for MaybeAsync<T>
impl<T> Unpin for MaybeAsync<T>where
T: Unpin,
impl<T> !UnwindSafe for MaybeAsync<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