Better document event context argument restrictions

master
Jonas Platte 2021-09-08 20:40:26 +02:00
parent c3e25bda1a
commit 699039f788
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
2 changed files with 13 additions and 3 deletions

View File

@ -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
///

View File

@ -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()