pub unsafe trait Event {
type This<'a>: 'a;
type EventIdx: EventIdxMarker;
type Mutability: MutabilityMarker;
// Provided method
fn init(world: &mut World) -> EventKind { ... }
}
Expand description
Messages which event handlers listen for. This is the base trait of
GlobalEvent
and TargetedEvent
.
To send and receive events within handlers, see Sender
and
Receiver
.
§Safety
This trait is unsafe
to implement because unsafe code relies on correct
implementations of This
and init
to avoid undefined behavior. Note
that implementations produced by the derive macros are always safe.
Required Associated Types§
sourcetype EventIdx: EventIdxMarker
type EventIdx: EventIdxMarker
Either GlobalEventIdx
or TargetedEventIdx
. This indicates if the
event is global or targeted.
sourcetype Mutability: MutabilityMarker
type Mutability: MutabilityMarker
Indicates if this event is Mutable
or Immutable
.
Immutable events disallow mutable references to the event and ownership
transfer via EventMut::take
. This is useful for ensuring events
are not altered during their lifespan.
Provided Methods§
sourcefn init(world: &mut World) -> EventKind
fn init(world: &mut World) -> EventKind
Gets the EventKind
of this event and performs any necessary
initialization work.
§Safety
Although this method is safe to call, it is unsafe to implement
because unsafe code relies on the returned EventKind
being correct
for this type. Additionally, the world
cannot be used in ways that
would result in dangling indices during handler initialization.
The exact safety requirements are currently unspecified, but the default
implementation returns EventKind::Normal
and is always safe.