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>
impl<E> Events<E>
Sourcepub fn send(&mut self, event: E)
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.
Sourcepub fn update(&mut self)
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.
Sourcepub fn read(&self, cursor: &mut EventCursor) -> impl Iterator<Item = &E>
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.