Module event_handler

Source
Expand description

Types and traits related for event handlers. For usage, see Client::add_event_handler.

§How it works

The add_event_handler method registers event handlers of different signatures by actually storing boxed closures that all have the same signature of async (EventHandlerData) -> () where EventHandlerData is a private type that contains all of the data an event handler might need.

The stored closure takes care of deserializing the event which the EventHandlerData contains as a (borrowed) serde_json::value::RawValue, extracting the context arguments from other fields of EventHandlerData and calling / .awaiting the event handler if the previous steps succeeded. It also logs any errors from the above chain of function calls.

For more details, see the EventHandler trait.

Structs§

Ctx
A custom value registered with .add_event_handler_context.
EventHandlerDropGuard
A guard type that removes an event handler when it drops (goes out of scope).
EventHandlerHandle
Handle to remove a registered event handler by passing it to Client::remove_event_handler.
EventHandlerSubscriber
The subscriber of an ObservableEventHandler.
ObservableEventHandler
An observer of events (may be tailored to a room).
RawEvent
The raw JSON form of an event.

Traits§

EventHandler
Interface for event handlers.
EventHandlerContext
Context for an event handler.
EventHandlerResult
Return types supported for event handlers implement this trait.
SyncEvent
A statically-known event kind/type that can be retrieved from an event sync.