Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime<RK: RuntimeKit> { /* private fields */ }
Expand description

A full-featured async runtime that combines an executor and a reactor.

Runtime<RK> wraps any RuntimeKit and adds higher-level helpers such as domain-name resolution (Runtime::to_socket_addrs) and runtime-shutdown error detection (Runtime::is_runtime_shutdown_error).

Concrete type aliases — NoopRuntime, SmolRuntime, TokioRuntime — are provided for each built-in backend and are the usual entry points.

Implementations§

Source§

impl<RK: RuntimeKit> Runtime<RK>

Source

pub fn new(kit: RK) -> Self

Create a new Runtime from a RuntimeKit

Source

pub fn to_socket_addrs<A: ToSocketAddrs + Send + 'static>( &self, addrs: A, ) -> SocketAddrsResolver<'_, RK, A>
where <A as ToSocketAddrs>::Iter: Send + 'static,

Asynchronously resolve the given domain name

Source

pub fn is_runtime_shutdown_error(&self, err: &Error) -> bool

Check if an std::io::Error is a runtime shutdown error

Only tokio’s shutdown error is recognised, and it is recognised by its value alone: no runtime is consulted, so the answer does not depend on which kit backs this Runtime nor on where the error came from. What this does not do is ask the kit about its own shutdown errors, so a SmolRuntime gets false for anything smol-specific.

Source§

impl Runtime<RuntimeParts<AsyncGlobalExecutor, AsyncIO>>

Source

pub fn async_global_executor() -> Self

Create a new AGERuntime

Source§

impl Runtime<Noop>

Source

pub fn noop() -> Self

Create a new NoopRuntime

Source§

impl Runtime<Smol>

Source

pub fn smol() -> Self

Create a new SmolRuntime

Source§

impl Runtime<Tokio>

Source

pub fn tokio() -> Result<Self>

Create a new TokioRuntime backed by a freshly created tokio multi-threaded runtime.

Source

pub fn tokio_current() -> Self

Create a new TokioRuntime and bind it to the current tokio runtime by default.

Source

pub fn tokio_with_handle(handle: Handle) -> Self

Create a new TokioRuntime and bind it to the tokio runtime associated to this handle by default.

Source

pub fn tokio_with_runtime(runtime: TokioRT) -> Self

Create a new TokioRuntime and bind it to this tokio runtime.

Trait Implementations§

Source§

impl<RK: Clone + RuntimeKit> Clone for Runtime<RK>

Source§

fn clone(&self) -> Runtime<RK>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<RK: Debug + RuntimeKit> Debug for Runtime<RK>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<RK: RuntimeKit> Executor for Runtime<RK>

Source§

type Task<T: Send + 'static> = <RK as Executor>::Task<T>

The type representing the tasks the are returned when spawning a Future on the executor
Source§

fn block_on<T, F: Future<Output = T>>(&self, f: F) -> T

Block on a future until completion
Source§

fn spawn<T: Send + 'static, F: Future<Output = T> + Send + 'static>( &self, f: F, ) -> Task<Self::Task<T>>

Spawn a future and return a handle to track its completion.
Source§

fn spawn_blocking<T: Send + 'static, F: FnOnce() -> T + Send + 'static>( &self, f: F, ) -> Task<Self::Task<T>>

Convert a blocking task into a future, spawning it on a dedicated thread pool
Source§

impl<RK: RuntimeKit> From<RK> for Runtime<RK>

Source§

fn from(kit: RK) -> Self

Converts to this type from the input type.
Source§

impl<RK: RuntimeKit> Reactor for Runtime<RK>

Source§

type TcpStream = <RK as Reactor>::TcpStream

The type representing a TCP stream (after tcp_connect) for this reactor
Source§

type Sleep = <RK as Reactor>::Sleep

A future that completes after a requested duration has elapsed (see Reactor::sleep)
Source§

fn register<H: Read + Write + AsSysFd + Send + 'static>( &self, socket: H, ) -> Result<impl AsyncRead + AsyncWrite + Send + Unpin + 'static>

Register a synchronous handle, returning an asynchronous one Read more
Source§

fn sleep(&self, dur: Duration) -> Self::Sleep

Sleep for the given duration
Source§

fn interval( &self, dur: Duration, ) -> impl Stream<Item = Instant> + Send + 'static

Stream that yields at every given interval
Source§

fn tcp_connect_addr( &self, addr: SocketAddr, ) -> impl Future<Output = Result<Self::TcpStream>> + Send + 'static

Create a TcpStream by connecting to a specific pre-resolved address
Source§

fn tcp_connect<A: AsyncToSocketAddrs + Send>( &self, addrs: A, ) -> impl Future<Output = Result<Self::TcpStream>> + Send
where Self: Sync + Sized,

Create a TcpStream by connecting to a remote host

Auto Trait Implementations§

§

impl<RK> Freeze for Runtime<RK>
where RK: Freeze,

§

impl<RK> RefUnwindSafe for Runtime<RK>
where RK: RefUnwindSafe,

§

impl<RK> Send for Runtime<RK>
where RK: Send,

§

impl<RK> Sync for Runtime<RK>
where RK: Sync,

§

impl<RK> Unpin for Runtime<RK>
where RK: Unpin,

§

impl<RK> UnsafeUnpin for Runtime<RK>
where RK: UnsafeUnpin,

§

impl<RK> UnwindSafe for Runtime<RK>
where RK: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more