Better document event context argument restrictions
This commit is contained in:
parent
c3e25bda1a
commit
699039f788
2 changed files with 13 additions and 3 deletions
|
@ -888,9 +888,13 @@ impl Client {
|
|||
/// [`Client`] also implements the `EventHandlerContext` trait
|
||||
/// so you don't have to clone your client into the event handler manually.
|
||||
///
|
||||
/// Invalid context arguments, for example a [`Room`][room::Room] as an
|
||||
/// argument to an account data event handler, will result in the event
|
||||
/// handler being skipped and an error logged.
|
||||
/// Some context arguments are not universally applicable. A context
|
||||
/// argument that isn't available for the given event type will result in
|
||||
/// the event handler being skipped and an error being logged. The following
|
||||
/// context argument types are only available for a subset of event types:
|
||||
///
|
||||
/// * [`Room`][room::Room] is only available for room-specific events, i.e.
|
||||
/// not for events like global account data events or presence events
|
||||
///
|
||||
/// [`EventHandlerContext`]: crate::event_handler::EventHandlerContext
|
||||
///
|
||||
|
|
|
@ -134,6 +134,12 @@ impl EventHandlerContext for Client {
|
|||
}
|
||||
}
|
||||
|
||||
/// This event handler context argument is only applicable to room-specific
|
||||
/// events.
|
||||
///
|
||||
/// Trying to use it in the event handler for another event, for example a
|
||||
/// global account data or presence event, will result in the event handler
|
||||
/// being skipped and an error getting logged.
|
||||
impl EventHandlerContext for room::Room {
|
||||
fn from_data(data: &EventHandlerData<'_>) -> Option<Self> {
|
||||
data.room.clone()
|
||||
|
|
Loading…
Reference in a new issue