Struct compio_runtime::Runtime

source ·
pub struct Runtime { /* private fields */ }
Expand description

The async runtime of compio. It is a thread local runtime, and cannot be sent to other threads.

Implementations§

source§

impl Runtime

source

pub fn new() -> Result<Self>

Create Runtime with default config.

source

pub fn builder() -> RuntimeBuilder

Create a builder for Runtime.

source

pub fn try_current() -> Option<Self>

Get the current running Runtime.

source

pub fn current() -> Self

Get the current running Runtime.

Panics

This method will panic if there are no running Runtime.

source

pub fn enter(&self) -> EnterGuard<'_>

Enter the runtime context. This runtime will be set as the current one.

Panics

When calling Runtime::enter multiple times, the returned guards must be dropped in the reverse order that they were acquired. Failure to do so will result in a panic and possible memory leaks.

Do not do the following, this shows a scenario that will result in a panic and possible memory leak.

use compio_runtime::Runtime;

let rt1 = Runtime::new().unwrap();
let rt2 = Runtime::new().unwrap();

let enter1 = rt1.enter();
let enter2 = rt2.enter();

drop(enter1);
drop(enter2);
source

pub fn block_on<F: Future>(&self, future: F) -> F::Output

Block on the future till it completes.

source

pub fn spawn<F: Future + 'static>(&self, future: F) -> Task<F::Output>

Spawns a new asynchronous task, returning a Task for it.

Spawning a task enables the task to execute concurrently to other tasks. There is no guarantee that a spawned task will execute to completion.

source

pub fn attach(&self, fd: RawFd) -> Result<()>

Attach a raw file descriptor/handle/socket to the runtime.

You only need this when authoring your own high-level APIs. High-level resources in this crate are attached automatically.

source

pub fn submit<T: OpCode + 'static>( &self, op: T ) -> impl Future<Output = BufResult<usize, T>>

Submit an operation to the runtime.

You only need this when authoring your own OpCode.

Trait Implementations§

source§

impl AsRawFd for Runtime

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl AsyncExecutor for &Runtime

Available on crate feature criterion only.
source§

fn block_on<T>(&self, future: impl Future<Output = T>) -> T

Spawn the given future onto this runtime and block until it’s complete, returning the result.
source§

impl AsyncExecutor for Runtime

Available on crate feature criterion only.
source§

fn block_on<T>(&self, future: impl Future<Output = T>) -> T

Spawn the given future onto this runtime and block until it’s complete, returning the result.
source§

impl Clone for Runtime

source§

fn clone(&self) -> Runtime

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Runtime

§

impl !Send for Runtime

§

impl !Sync for Runtime

§

impl Unpin for Runtime

§

impl !UnwindSafe for Runtime

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

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

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

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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