Skip to main content

Event

Trait Event 

Source
pub trait Event:
    Serialize
    + Send
    + Sync
    + 'static {
    const ID: &'static str;

    // Provided methods
    fn id(&self) -> &str { ... }
    fn schema(&self) -> Option<Value> { ... }
}
Expand description

A typed event payload.

Implementations pair a compile-time string id with a Serialize payload. The struct itself is the payload — serde_json::to_value on an instance produces what goes on the wire.

§Compile-time vs runtime events

  • Compile-time: const ID / const DESCRIPTION and the #[event] macro. The defaults for id and description read these constants.
  • Runtime: use DynEvent to supply an owned String id, description, and payload. DynEvent implements Event by overriding the instance-level methods.

Both paths emit through the same emit entry point.

Required Associated Constants§

Source

const ID: &'static str

Compile-time event identifier. Ignored when a value overrides id to return a runtime string (as DynEvent does).

Identifiers prefixed with _ are treated as private: they fire only to local listeners and are never broadcast to connected channels.

Provided Methods§

Source

fn id(&self) -> &str

Instance-level id. Defaults to ID; DynEvent overrides this to return a runtime-owned id.

Source

fn schema(&self) -> Option<Value>

Wire-level JSON Schema for the payload, if one is available. The #[event] macro overrides this with a schema derived from schemars.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Event for DynEvent

Source§

const ID: &'static str = ""