Struct rodbus::MaybeAsync

source ·
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§

Retrieve the value, which might be available immediately or require awaiting

Construct a new MaybeAsync from an already available result

Construct a new MaybeAsync from a future which yields the value eventually

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more