cargo fmt/clippy

master
Devin R 2020-03-31 22:00:46 -04:00
parent f2b50677b9
commit 5c418f3420
4 changed files with 69 additions and 23 deletions

View File

@ -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::{

View File

@ -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<tokio::sync::Mutex<Box<dyn EventEmitter>>>) {
pub async fn add_event_emitter(
&mut self,
emitter: Arc<tokio::sync::Mutex<Box<dyn EventEmitter>>>,
) {
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<String> {
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.

View File

@ -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;
}
}

View File

@ -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<Mutex<Room>>, _: Arc<Mutex<NonRoomEvent>>) {}
/// Fires when `AsyncClient` receives a `NonRoomEvent::RoomName` event.
async fn on_account_ignored_users(&mut self, _: Arc<Mutex<Room>>, _: Arc<Mutex<NonRoomEvent>>) {}
async fn on_account_ignored_users(&mut self, _: Arc<Mutex<Room>>, _: Arc<Mutex<NonRoomEvent>>) {
}
/// Fires when `AsyncClient` receives a `NonRoomEvent::RoomCanonicalAlias` event.
async fn on_account_push_rules(&mut self, _: Arc<Mutex<Room>>, _: Arc<Mutex<NonRoomEvent>>) {}
/// Fires when `AsyncClient` receives a `NonRoomEvent::RoomAliases` event.
async fn on_account_data_fully_read(&mut self, _: Arc<Mutex<Room>>, _: Arc<Mutex<NonRoomEvent>>) {}
async fn on_account_data_fully_read(
&mut self,
_: Arc<Mutex<Room>>,
_: Arc<Mutex<NonRoomEvent>>,
) {
}
// `PresenceEvent` is a struct so there is only the one method
/// Fires when `AsyncClient` receives a `NonRoomEvent::RoomAliases` event.