Skip to main content

Events

Struct Events 

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

An ordered, game-owned event queue. No hidden dispatch or subscriptions.

Producers call Self::send, readers inspect Self::read, and the game clears or drains the queue at an explicit phase boundary. Several readers can see the same events before clear. Preallocate for hot simulation paths.

use rayengine_core::events::Events;
struct Hit { damage: u32 }
let mut hits = Events::with_capacity(32);
hits.send(Hit { damage: 12 });
assert_eq!(hits.read().iter().map(|h| h.damage).sum::<u32>(), 12);
// Consume once, retaining capacity for the next tick.
assert_eq!(hits.drain().count(), 1);
assert!(hits.read().is_empty());

Implementations§

Source§

impl<T> Events<T>

Source

pub fn with_capacity(capacity: usize) -> Self

Empty queue with reserved event capacity.

Source

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

Appends a game event. Grows if reserved capacity is exceeded.

Source

pub fn read(&self) -> &[T]

Events in production order. Reading does not consume them.

Source

pub fn drain(&mut self) -> Drain<'_, T> ⓘ

Consumes events in order, retaining the queue’s storage.

Source

pub fn clear(&mut self)

Drops all events, retaining storage for the next phase/tick.

Source

pub fn capacity(&self) -> usize

Reserved slots, useful when planning an allocation budget.

Trait Implementations§

Source§

impl<T: Debug> Debug for Events<T>

Source§

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

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

impl<T> Default for Events<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for Events<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for Events<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for Events<T>
where Vec<T>: Send,

§

impl<T> Sync for Events<T>
where Vec<T>: Sync,

§

impl<T> Unpin for Events<T>
where Vec<T>: Unpin,

§

impl<T> UnsafeUnpin for Events<T>
where Vec<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Events<T>
where Vec<T>: 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> Component for T
where T: Send + Sync + 'static,

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.