pub trait AsyncRuntime:
Debug
+ Default
+ PartialEq
+ Eq
+ OptionalSend
+ OptionalSync
+ 'static {
type JoinError: Debug + Display + OptionalSend;
type JoinHandle<T: OptionalSend + 'static>: Future<Output = Result<T, Self::JoinError>> + OptionalSend + OptionalSync + Unpin;
type Sleep: Future<Output = ()> + OptionalSend + OptionalSync;
type Instant: Instant;
type TimeoutError: Debug + Display + OptionalSend;
type Timeout<R, T: Future<Output = R> + OptionalSend>: Future<Output = Result<R, Self::TimeoutError>> + OptionalSend;
type ThreadLocalRng: Rng;
type OneshotSender<T: OptionalSend>: AsyncOneshotSendExt<T> + OptionalSend + OptionalSync + Debug;
type OneshotReceiverError: Error + OptionalSend;
type OneshotReceiver<T: OptionalSend>: OptionalSend + OptionalSync + Future<Output = Result<T, Self::OneshotReceiverError>> + Unpin;
// Required methods
fn spawn<T>(future: T) -> Self::JoinHandle<<T as Future>::Output>
where T: Future + OptionalSend + 'static,
<T as Future>::Output: OptionalSend + 'static;
fn sleep(duration: Duration) -> Self::Sleep;
fn sleep_until(deadline: Self::Instant) -> Self::Sleep;
fn timeout<R, F>(duration: Duration, future: F) -> Self::Timeout<R, F>
where F: Future<Output = R> + OptionalSend;
fn timeout_at<R, F>(
deadline: Self::Instant,
future: F,
) -> Self::Timeout<R, F>
where F: Future<Output = R> + OptionalSend;
fn is_panic(join_error: &Self::JoinError) -> bool;
fn thread_rng() -> Self::ThreadLocalRng;
fn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)
where T: OptionalSend;
}Expand description
A trait defining interfaces with an asynchronous runtime.
The intention of this trait is to allow an application using this crate to bind an asynchronous runtime that suits it the best.
Some additional related functions are also exposed by this trait.
§Note
The default asynchronous runtime is tokio.
Required Associated Types§
Sourcetype JoinError: Debug + Display + OptionalSend
type JoinError: Debug + Display + OptionalSend
The error type of Self::JoinHandle.
Sourcetype JoinHandle<T: OptionalSend + 'static>: Future<Output = Result<T, Self::JoinError>> + OptionalSend + OptionalSync + Unpin
type JoinHandle<T: OptionalSend + 'static>: Future<Output = Result<T, Self::JoinError>> + OptionalSend + OptionalSync + Unpin
The return type of Self::spawn.
Sourcetype Sleep: Future<Output = ()> + OptionalSend + OptionalSync
type Sleep: Future<Output = ()> + OptionalSend + OptionalSync
The type that enables the user to sleep in an asynchronous runtime.
Sourcetype TimeoutError: Debug + Display + OptionalSend
type TimeoutError: Debug + Display + OptionalSend
The timeout error type.
Sourcetype Timeout<R, T: Future<Output = R> + OptionalSend>: Future<Output = Result<R, Self::TimeoutError>> + OptionalSend
type Timeout<R, T: Future<Output = R> + OptionalSend>: Future<Output = Result<R, Self::TimeoutError>> + OptionalSend
The timeout type used by Self::timeout and Self::timeout_at that enables the user
to await the outcome of a Future.
Sourcetype ThreadLocalRng: Rng
type ThreadLocalRng: Rng
Type of a thread-local random number generator.
Sourcetype OneshotSender<T: OptionalSend>: AsyncOneshotSendExt<T> + OptionalSend + OptionalSync + Debug
type OneshotSender<T: OptionalSend>: AsyncOneshotSendExt<T> + OptionalSend + OptionalSync + Debug
Type of a oneshot sender.
Sourcetype OneshotReceiverError: Error + OptionalSend
type OneshotReceiverError: Error + OptionalSend
Type of a oneshot receiver error.
Sourcetype OneshotReceiver<T: OptionalSend>: OptionalSend + OptionalSync + Future<Output = Result<T, Self::OneshotReceiverError>> + Unpin
type OneshotReceiver<T: OptionalSend>: OptionalSend + OptionalSync + Future<Output = Result<T, Self::OneshotReceiverError>> + Unpin
Type of a oneshot receiver.
Required Methods§
Sourcefn spawn<T>(future: T) -> Self::JoinHandle<<T as Future>::Output>
fn spawn<T>(future: T) -> Self::JoinHandle<<T as Future>::Output>
Spawn a new task.
Sourcefn sleep_until(deadline: Self::Instant) -> Self::Sleep
fn sleep_until(deadline: Self::Instant) -> Self::Sleep
Wait until deadline is reached.
Sourcefn timeout<R, F>(duration: Duration, future: F) -> Self::Timeout<R, F>where
F: Future<Output = R> + OptionalSend,
fn timeout<R, F>(duration: Duration, future: F) -> Self::Timeout<R, F>where
F: Future<Output = R> + OptionalSend,
Require a Future to complete before the specified duration has elapsed.
Sourcefn timeout_at<R, F>(deadline: Self::Instant, future: F) -> Self::Timeout<R, F>where
F: Future<Output = R> + OptionalSend,
fn timeout_at<R, F>(deadline: Self::Instant, future: F) -> Self::Timeout<R, F>where
F: Future<Output = R> + OptionalSend,
Require a Future to complete before the specified instant in time.
Sourcefn is_panic(join_error: &Self::JoinError) -> bool
fn is_panic(join_error: &Self::JoinError) -> bool
Check if the Self::JoinError is panic.
Sourcefn thread_rng() -> Self::ThreadLocalRng
fn thread_rng() -> Self::ThreadLocalRng
Get the random number generator to use for generating random numbers.
§Note
This is a per-thread instance, which cannot be shared across threads or sent to another thread.
Sourcefn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)where
T: OptionalSend,
fn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)where
T: OptionalSend,
Creates a new one-shot channel for sending single values.
The function returns separate “send” and “receive” handles. The Sender
handle is used by the producer to send the value. The Receiver handle is
used by the consumer to receive the value.
Each handle can be used on separate tasks.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".