diff --git a/examples/login.rs b/examples/login.rs index 8727f5f7..bf612b8d 100644 --- a/examples/login.rs +++ b/examples/login.rs @@ -1,6 +1,6 @@ +use std::ops::{Deref, DerefMut}; use std::sync::{Arc, RwLock}; use std::{env, process::exit}; -use std::ops::{Deref, DerefMut}; use url::Url; use matrix_sdk::{ diff --git a/src/async_client.rs b/src/async_client.rs index 0799dfef..94ad4e03 100644 --- a/src/async_client.rs +++ b/src/async_client.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; use std::convert::{TryFrom, TryInto}; use std::result::Result as StdResult; use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use std::time::{Duration, Instant}; use futures::future::{BoxFuture, Future, FutureExt}; @@ -263,13 +263,20 @@ impl AsyncClient { /// Add `EventEmitter` to `AsyncClient`. /// /// The methods of `EventEmitter` are called when the respective `RoomEvents` occur. - pub async fn add_event_emitter(&mut self, emitter: Arc>>) { + pub async fn add_event_emitter( + &mut self, + emitter: Arc>>, + ) { self.base_client.write().await.event_emitter = Some(emitter); } /// Calculates the room name from a `RoomId`, returning a string. pub async fn get_room_name(&self, room_id: &str) -> Option { - self.base_client.read().await.calculate_room_name(room_id).await + self.base_client + .read() + .await + .calculate_room_name(room_id) + .await } /// Calculates the room names this client knows about. diff --git a/src/base_client.rs b/src/base_client.rs index 6800657e..012d7679 100644 --- a/src/base_client.rs +++ b/src/base_client.rs @@ -16,7 +16,7 @@ use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::fmt; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; #[cfg(feature = "encryption")] use std::result::Result as StdResult; @@ -302,10 +302,7 @@ impl Client { } } - let mut room = self - .get_or_create_room(&room_id.to_string()) - .lock() - .await; + let mut room = self.get_or_create_room(&room_id.to_string()).lock().await; room.receive_timeline_event(e); decrypted_event } @@ -527,7 +524,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_room_canonical_alias(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_room_canonical_alias( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -567,7 +567,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_room_message_feedback(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_room_message_feedback( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -577,7 +580,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_room_redaction(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_room_redaction( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -587,7 +593,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_room_power_levels(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_room_power_levels( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -623,7 +632,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_state_canonical_alias(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_state_canonical_alias( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -633,7 +645,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_state_aliases(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_state_aliases( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -653,7 +668,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_state_power_levels(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_state_power_levels( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -663,7 +681,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_state_join_rules(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_state_join_rules( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -683,7 +704,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_account_presence(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_account_presence( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -693,7 +717,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_account_ignored_users(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_account_ignored_users( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -703,7 +730,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_account_push_rules(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_account_push_rules( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } @@ -713,7 +743,10 @@ impl Client { if let Some(room) = self.get_room(&room_id.to_string()) { ee.lock() .await - .on_account_data_fully_read(Arc::clone(&room), Arc::new(Mutex::new(event.clone()))) + .on_account_data_fully_read( + Arc::clone(&room), + Arc::new(Mutex::new(event.clone())), + ) .await; } } diff --git a/src/event_emitter/mod.rs b/src/event_emitter/mod.rs index 0c962e07..20612260 100644 --- a/src/event_emitter/mod.rs +++ b/src/event_emitter/mod.rs @@ -64,11 +64,17 @@ pub trait EventEmitter: Send + Sync { /// Fires when `AsyncClient` receives a `NonRoomEvent::RoomMember` event. async fn on_account_presence(&mut self, _: Arc>, _: Arc>) {} /// Fires when `AsyncClient` receives a `NonRoomEvent::RoomName` event. - async fn on_account_ignored_users(&mut self, _: Arc>, _: Arc>) {} + async fn on_account_ignored_users(&mut self, _: Arc>, _: Arc>) { + } /// Fires when `AsyncClient` receives a `NonRoomEvent::RoomCanonicalAlias` event. async fn on_account_push_rules(&mut self, _: Arc>, _: Arc>) {} /// Fires when `AsyncClient` receives a `NonRoomEvent::RoomAliases` event. - async fn on_account_data_fully_read(&mut self, _: Arc>, _: Arc>) {} + async fn on_account_data_fully_read( + &mut self, + _: Arc>, + _: Arc>, + ) { + } // `PresenceEvent` is a struct so there is only the one method /// Fires when `AsyncClient` receives a `NonRoomEvent::RoomAliases` event.