Allow chaining .register_event_handler()

master
Jonas Platte 2021-09-08 23:32:39 +02:00
parent 8c499a63dc
commit 6e571c579d
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
1 changed files with 14 additions and 9 deletions

View File

@ -917,14 +917,17 @@ impl Client {
/// };
/// use serde::{Deserialize, Serialize};
///
/// client.register_event_handler(
/// |ev: SyncMessageEvent<MessageEventContent>, room: Room, client: Client| async move {
/// // Common usage: Room event plus room and client.
/// },
/// ).await;
/// client.register_event_handler(|ev: SyncStateEvent<TopicEventContent>| async move {
/// // Also possible: Omit any or all arguments after the first.
/// }).await;
/// client
/// .register_event_handler(
/// |ev: SyncMessageEvent<MessageEventContent>, room: Room, client: Client| async move {
/// // Common usage: Room event plus room and client.
/// },
/// )
/// .await
/// .register_event_handler(|ev: SyncStateEvent<TopicEventContent>| async move {
/// // Also possible: Omit any or all arguments after the first.
/// })
/// .await;
///
/// // Custom events work exactly the same way, you just need to declare the content struct and
/// // use the EventContent derive macro on it.
@ -942,7 +945,7 @@ impl Client {
/// },
/// ).await;
/// ```
pub async fn register_event_handler<Ev, Ctx, H>(&self, handler: H)
pub async fn register_event_handler<Ev, Ctx, H>(&self, handler: H) -> &Self
where
Ev: SyncEvent + DeserializeOwned + Send + 'static,
H: EventHandler<Ev, Ctx>,
@ -972,6 +975,8 @@ impl Client {
}
.boxed()
}));
self
}
/// Get all the rooms the client knows about.