pub struct Events<T> { /* private fields */ }Expand description
The events of type T: a resource of the World with two buffers, the events of the last
two updates (DECISIONS #26).
A Schedule updates it at its sync point, at the end of every
run: the older buffer is dropped, then the events the systems’ writers
sent during the frame are appended in system registration order. Every event has a running
id, so a reader that keeps an EventCursor sees every event once, as long as it reads at
least once every two updates. The schedule creates the resource for every event type its
systems use; World::send_event creates it on the first event.
use pragma_ecs::{EventCursor, Events};
let mut events = Events::<&str>::new();
let mut cursor = EventCursor::default();
events.send("hello")?;
assert_eq!(cursor.read(&events).copied().collect::<Vec<_>>(), ["hello"]);
events.update(); // "hello" is still kept for one more update
events.send("world")?;
assert_eq!(events.len(), 2);
assert_eq!(cursor.read(&events).copied().collect::<Vec<_>>(), ["world"]);
events.update();
events.update(); // both are gone
assert!(events.is_empty());Implementations§
Source§impl<T> Events<T>
impl<T> Events<T>
Sourcepub fn send(&mut self, event: T) -> Result<(), EcsError>
pub fn send(&mut self, event: T) -> Result<(), EcsError>
Appends event to the current buffer.
§Errors
EcsError::OutOfMemory if the buffer cannot grow; the event is dropped.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Events<T>
impl<T> RefUnwindSafe for Events<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for Events<T>
impl<T> Sync for Events<T>
impl<T> Unpin for Events<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more