pub struct RuntimeEventBus { /* private fields */ }Expand description
Typed per-frame event accumulator for runtime plugin communication.
Stored on super::output::RuntimeOutput and accessible via ctx.output.events
from any plugin step. Events accumulate during the frame and are returned to the
app in super::output::RuntimeOutput at the end of each super::ViewportRuntime::step call.
Events are cleared each frame because RuntimeOutput is constructed fresh on
every step call. Use super::resources::RuntimeResources for state that
must persist across frames.
The event type IS the category. Define a distinct struct for each kind of event your plugin emits. Multiple plugins can emit events of the same type; all accumulate and are visible together.
§Example
// Emit from a plugin step.
ctx.output.events.emit(TriggerEntered { trigger_id, actor_id });
// Read from a later plugin in the same frame.
for ev in ctx.output.events.read::<TriggerEntered>() { ... }
// Read from the app after step() returns.
for ev in output.events.read::<TriggerEntered>() { ... }
// Drain (take ownership) after step() returns.
for ev in output.events.drain::<TriggerEntered>() { ... }Implementations§
Source§impl RuntimeEventBus
impl RuntimeEventBus
Sourcepub fn emit<T: Send + 'static>(&mut self, event: T)
pub fn emit<T: Send + 'static>(&mut self, event: T)
Emit an event. Multiple calls accumulate; all are visible to later readers.
Sourcepub fn read<T: Send + 'static>(&self) -> impl Iterator<Item = &T> + '_
pub fn read<T: Send + 'static>(&self) -> impl Iterator<Item = &T> + '_
Iterate over all events of type T emitted this frame.
Sourcepub fn drain<T: Send + 'static>(&mut self) -> Vec<T>
pub fn drain<T: Send + 'static>(&mut self) -> Vec<T>
Remove and return all events of type T, leaving the slot empty.
Calling this twice for the same type returns an empty vec on the second call.
Trait Implementations§
Source§impl Default for RuntimeEventBus
impl Default for RuntimeEventBus
Source§fn default() -> RuntimeEventBus
fn default() -> RuntimeEventBus
Auto Trait Implementations§
impl !RefUnwindSafe for RuntimeEventBus
impl !Sync for RuntimeEventBus
impl !UnwindSafe for RuntimeEventBus
impl Freeze for RuntimeEventBus
impl Send for RuntimeEventBus
impl Unpin for RuntimeEventBus
impl UnsafeUnpin for RuntimeEventBus
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.