Skip to content

Commit 038adea

Browse files
committed
appservice: Examples for query handler registry fns
Add examples for functions for registering handlers for room and user queries. Also remove a needless mut requirement for these functions.
1 parent c79e62d commit 038adea

File tree

1 file changed

+24
-2
lines changed
  • crates/matrix-sdk-appservice/src

1 file changed

+24
-2
lines changed

crates/matrix-sdk-appservice/src/lib.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,19 @@ impl AppService {
408408
/// given mxid.
409409
///
410410
/// See [GET /_matrix/app/v1/users/{userId}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-users-userid).
411+
///
412+
/// # Example
413+
/// ```no_run
414+
/// # use matrix_sdk_appservice::AppService;
415+
/// # fn run(appservice: AppService) {
416+
/// appservice.register_user_query(Box::new(|appservice, req| Box::pin(async move {
417+
/// println!("Got request for {}", req.user_id);
418+
/// true
419+
/// })));
420+
/// # }
421+
/// ```
411422
pub async fn register_user_query(
412-
&mut self,
423+
&self,
413424
handler: AppserviceFn<query_user::IncomingRequest, bool>,
414425
) {
415426
*self.event_handler.users.lock().await = Some(handler);
@@ -419,8 +430,19 @@ impl AppService {
419430
/// given alias.
420431
///
421432
/// See [GET /_matrix/app/v1/rooms/{roomAlias}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-rooms-roomalias).
433+
///
434+
/// # Example
435+
/// ```no_run
436+
/// # use matrix_sdk_appservice::AppService;
437+
/// # fn run(appservice: AppService) {
438+
/// appservice.register_room_query(Box::new(|appservice, req| Box::pin(async move {
439+
/// println!("Got request for {}", req.room_alias);
440+
/// true
441+
/// })));
442+
/// # }
443+
/// ```
422444
pub async fn register_room_query(
423-
&mut self,
445+
&self,
424446
handler: AppserviceFn<query_room::IncomingRequest, bool>,
425447
) {
426448
*self.event_handler.rooms.lock().await = Some(handler);

0 commit comments

Comments
 (0)