Skip to main content

Context

Struct Context 

Source
pub struct Context<'a, E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> { /* private fields */ }
Expand description

A handle of the event loop that you are currently in.

Used to spawn tasks, sleep, dispatch events to the external world and start IO operations.

§Panics

Wakers can only be woken on the same thread that created an EventLoop, otherwise waking panics.

Implementations§

Source§

impl<'a, E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

Source

pub fn dispatch(&self, event: E) -> Result<(), E>

Pushes given event into the queue that EventLoop::events pops from.

§Errors

Returns event back if the queue already holds EVENTS events.

Source

pub fn spawn<F, Fut>( &self, f: F, ) -> Result<impl Future<Output = ()> + use<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS, F, Fut>, NotEnoughResources>
where F: FnOnce(Self) -> Fut, Fut: Future<Output = ()> + 'a,

Spawns a task with a given async closure.

The future must fit TASK_SIZE bytes and be aligned to at most 16 bytes, otherwise the program doesn’t compile.

Returns a join handle, a future that resolves once the task is finished. Dropping it detaches the task, which keeps running until it finishes.

§Errors

Returns an error if all TASKS task slots are taken, the future returned by f is dropped without being polled then. Use reserve_task to wait for a free slot instead.

Source

pub fn reserve_task( &self, ) -> impl Future<Output = Result<TaskReservation<'a, TASKS, TASK_SIZE, ROOT_TASK_SIZE>, SlotWaiterTakenError>> + use<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

Reserves a task slot.

This method returns a future that is resolved once a slot in the internal pool of tasks is available.

The future stays pending until some other task finishes and frees a slot.

§Errors

Only one task can wait for a free slot at a time. The future resolves to SlotWaiterTakenError if all TASKS slots are taken and another task already waits.

§Cancel safety

This method is cancel safe.

Source

pub fn sleep( &self, duration: Duration, ) -> impl Future<Output = Result<(), NotEnoughResources>> + use<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

Sleeps for duration.

§Errors

The returned future resolves to an error if all TIMERS timer slots are taken.

§Cancel safety

This method is cancel safe.

Source

pub fn timeout<F: Future>( &self, duration: Duration, future: F, ) -> impl Future<Output = Result<MaybeTimedOut<F::Output>, NotEnoughResources>>

Runs future with a timeout of duration, resolves to Ok(MaybeTimedOut::Timeout) in case of a timeout.

§Errors

The returned future resolves to an error if all TIMERS timer slots are taken.

§Cancel safety

This method is cancel safe if future is.

Source

pub fn notified( &self, ) -> impl Future<Output = ()> + use<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

Waits until EventLoop::notify is called.

Notifications don’t queue up: any number of notify() calls made before the future is polled resolve it only once.

Only one task can wait for a notification at a time.

§Cancel safety

This method is cancel safe.

Trait Implementations§

Source§

impl<E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Clone for Context<'_, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

Source§

fn clone(&self) -> Self

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<E: 'static, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Copy for Context<'_, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

Auto Trait Implementations§

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> !RefUnwindSafe for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> !Send for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> !Sync for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> !UnwindSafe for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Forget for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Freeze for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
where &'static LoopStorage<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>: Freeze,

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Move for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> Unpin for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
where &'static LoopStorage<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>: Unpin,

§

impl<'a, E, const EVENTS: usize, const TASKS: usize, const TASK_SIZE: usize, const ROOT_TASK_SIZE: usize, const TIMERS: usize, const FDS: usize> UnsafeUnpin for Context<'a, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
where &'static LoopStorage<E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>: UnsafeUnpin,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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, !>

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.