Skip to main content

Events

Struct Events 

Source
pub struct Events<E> { /* private fields */ }
Expand description

A double-buffered event queue: events stay readable for two frames.

Implementations§

Source§

impl<E> Events<E>

Source

pub fn new() -> Events<E>

An empty queue.

Source

pub fn send(&mut self, event: E)

Queue an event. It becomes visible to readers immediately and stays readable until the second update after this one.

Source

pub fn update(&mut self)

Advance one frame: retire the older buffer and start a fresh newest one. Events older than two cycles are dropped.

Source

pub fn read(&self, cursor: &mut EventCursor) -> impl Iterator<Item = &E>

Read every buffered event the cursor has not yet seen, in send order, and advance the cursor past them.

Lazy: a drain costs no allocation, which matters because every event reader does this every frame. The cursor advances here rather than as the iterator is consumed, so a caller that reads only part of the run still ends up past all of it – the same thing a returned collection did, and the only behaviour that makes “every reader sees every event exactly once” hold for a partial read.

Source

pub fn len(&self) -> usize

Total events currently buffered across both frames.

Source

pub fn is_empty(&self) -> bool

Whether both frame buffers are empty.

Trait Implementations§

Source§

impl<E> Default for Events<E>

Source§

fn default() -> Events<E>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E> Freeze for Events<E>
where [Vec<E>; 2]: Freeze,

§

impl<E> RefUnwindSafe for Events<E>
where [Vec<E>; 2]: RefUnwindSafe,

§

impl<E> Send for Events<E>
where [Vec<E>; 2]: Send,

§

impl<E> Sync for Events<E>
where [Vec<E>; 2]: Sync,

§

impl<E> Unpin for Events<E>
where [Vec<E>; 2]: Unpin,

§

impl<E> UnsafeUnpin for Events<E>
where [Vec<E>; 2]: UnsafeUnpin,

§

impl<E> UnwindSafe for Events<E>
where [Vec<E>; 2]: 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> 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, <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.