From 91afa1e0e025695b677eec0ddade248c184efe8e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 13 Oct 2021 11:56:46 +0200 Subject: [PATCH] Make Result alias usable with any error type --- src/client_server/sync.rs | 4 ++-- src/database/proxy.rs | 4 ++-- src/database/sending.rs | 2 +- src/error.rs | 2 +- src/server_server.rs | 16 +++++++--------- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs index 284aeb06..e4c12c40 100644 --- a/src/client_server/sync.rs +++ b/src/client_server/sync.rs @@ -60,7 +60,7 @@ use rocket::{get, tokio}; pub async fn sync_events_route( db: DatabaseGuard, body: Ruma>, -) -> std::result::Result, RumaResponse> { +) -> Result, RumaResponse> { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_device = body.sender_device.as_ref().expect("user is authenticated"); @@ -182,7 +182,7 @@ async fn sync_helper( full_state: bool, timeout: Option, // bool = caching allowed -) -> std::result::Result<(sync_events::Response, bool), Error> { +) -> Result<(sync_events::Response, bool), Error> { // TODO: match body.set_presence { db.rooms.edus.ping_presence(&sender_user)?; diff --git a/src/database/proxy.rs b/src/database/proxy.rs index 33f7f3d9..fb0387c9 100644 --- a/src/database/proxy.rs +++ b/src/database/proxy.rs @@ -125,7 +125,7 @@ impl WildCardedDomain { } impl std::str::FromStr for WildCardedDomain { type Err = std::convert::Infallible; - fn from_str(s: &str) -> std::result::Result { + fn from_str(s: &str) -> Result { // maybe do some domain validation? Ok(if s.starts_with("*.") { WildCardedDomain::WildCarded(s[1..].to_owned()) @@ -137,7 +137,7 @@ impl std::str::FromStr for WildCardedDomain { } } impl<'de> Deserialize<'de> for WildCardedDomain { - fn deserialize(deserializer: D) -> std::result::Result + fn deserialize(deserializer: D) -> Result where D: serde::de::Deserializer<'de>, { diff --git a/src/database/sending.rs b/src/database/sending.rs index b4acce1d..bf0cc2c1 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -485,7 +485,7 @@ impl Sending { kind: OutgoingKind, events: Vec, db: Arc>, - ) -> std::result::Result { + ) -> Result { let db = db.read().await; match &kind { diff --git a/src/error.rs b/src/error.rs index 1ecef3aa..7faddc91 100644 --- a/src/error.rs +++ b/src/error.rs @@ -20,7 +20,7 @@ use { tracing::error, }; -pub type Result = std::result::Result; +pub type Result = std::result::Result; #[derive(Error, Debug)] pub enum Error { diff --git a/src/server_server.rs b/src/server_server.rs index cb00baaf..68e262b4 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -65,7 +65,6 @@ use std::{ mem, net::{IpAddr, SocketAddr}, pin::Pin, - result::Result as StdResult, sync::{Arc, RwLock, RwLockWriteGuard}, time::{Duration, Instant, SystemTime}, }; @@ -956,7 +955,7 @@ pub(crate) async fn handle_incoming_pdu<'a>( is_timeline_event: bool, db: &'a Database, pub_key_map: &'a RwLock>>, -) -> StdResult>, String> { +) -> Result>, String> { match db.rooms.exists(room_id) { Ok(true) => {} _ => { @@ -1137,8 +1136,7 @@ fn handle_outlier_pdu<'a>( value: BTreeMap, db: &'a Database, pub_key_map: &'a RwLock>>, -) -> AsyncRecursiveType<'a, StdResult<(Arc, BTreeMap), String>> -{ +) -> AsyncRecursiveType<'a, Result<(Arc, BTreeMap), String>> { Box::pin(async move { // TODO: For RoomVersion6 we must check that Raw<..> is canonical do we anywhere?: https://matrix.org/docs/spec/rooms/v6#canonical-json @@ -1301,7 +1299,7 @@ async fn upgrade_outlier_to_timeline_pdu( db: &Database, room_id: &RoomId, pub_key_map: &RwLock>>, -) -> StdResult>, String> { +) -> Result>, String> { if let Ok(Some(pduid)) = db.rooms.get_pdu_id(&incoming_pdu.event_id) { return Ok(Some(pduid)); } @@ -1448,7 +1446,7 @@ async fn upgrade_outlier_to_timeline_pdu( .map_err(|_| "Failed to get_or_create_shortstatekey".to_owned())?; Ok((shortstatekey, Arc::new(event_id))) }) - .collect::>()?, + .collect::>()?, ), Err(e) => { warn!("State resolution on prev events failed, either an event could not be found or deserialization: {}", e); @@ -1630,7 +1628,7 @@ async fn upgrade_outlier_to_timeline_pdu( .compress_state_event(*shortstatekey, id, &db.globals) .map_err(|_| "Failed to compress_state_event".to_owned()) }) - .collect::>()?; + .collect::>()?; // 13. Check if the event passes auth based on the "current state" of the room, if not "soft fail" it debug!("starting soft fail auth check"); @@ -1750,7 +1748,7 @@ async fn upgrade_outlier_to_timeline_pdu( .compress_state_event(*k, id, &db.globals) .map_err(|_| "Failed to compress_state_event.".to_owned()) }) - .collect::>()? + .collect::>()? } else { // We do need to force an update to this room's state update_state = true; @@ -1812,7 +1810,7 @@ async fn upgrade_outlier_to_timeline_pdu( .compress_state_event(shortstatekey, &event_id, &db.globals) .map_err(|_| "Failed to compress state event".to_owned()) }) - .collect::>()? + .collect::>()? }; // Set the new room state to the resolved state