From 919735b4ce8b417e60b408ae4cce2f7638ac0be6 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 3 Jun 2024 01:58:26 -0400 Subject: [PATCH] remove usages of `&String` and `&Owned[..]` Signed-off-by: strawberry --- src/admin/handler.rs | 4 ++-- src/admin/utils.rs | 6 +++--- src/api/client_server/alias.rs | 6 +++--- src/api/client_server/room.rs | 4 ++-- src/api/client_server/sync.rs | 2 +- src/service/admin.rs | 4 ++-- src/service/sending/sender.rs | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/admin/handler.rs b/src/admin/handler.rs index 7b7396ef..1a2ff38e 100644 --- a/src/admin/handler.rs +++ b/src/admin/handler.rs @@ -8,7 +8,7 @@ use ruma::{ room::message::{Relation::Reply, RoomMessageEventContent}, TimelineEventType, }, - OwnedRoomId, OwnedUserId, ServerName, UserId, + OwnedRoomId, OwnedUserId, RoomId, ServerName, UserId, }; use serde_json::value::to_raw_value; use tokio::sync::MutexGuard; @@ -125,7 +125,7 @@ async fn handle_event(event: AdminRoomEvent, admin_room: OwnedRoomId, server_use } async fn handle_response_error( - e: &Error, admin_room: &OwnedRoomId, server_user: &UserId, state_lock: &MutexGuard<'_, ()>, + e: &Error, admin_room: &RoomId, server_user: &UserId, state_lock: &MutexGuard<'_, ()>, ) -> Result<()> { error!("Failed to build and append admin room response PDU: \"{e}\""); let error_room_message = RoomMessageEventContent::text_plain(format!( diff --git a/src/admin/utils.rs b/src/admin/utils.rs index 7031b848..6e65f2b2 100644 --- a/src/admin/utils.rs +++ b/src/admin/utils.rs @@ -1,5 +1,5 @@ pub(crate) use conduit::utils::HtmlEscape; -use ruma::OwnedRoomId; +use ruma::{OwnedRoomId, RoomId}; use crate::services; @@ -9,9 +9,9 @@ pub(crate) fn escape_html(s: &str) -> String { .replace('>', ">") } -pub(crate) fn get_room_info(id: &OwnedRoomId) -> (OwnedRoomId, u64, String) { +pub(crate) fn get_room_info(id: &RoomId) -> (OwnedRoomId, u64, String) { ( - id.clone(), + id.into(), services() .rooms .state_cache diff --git a/src/api/client_server/alias.rs b/src/api/client_server/alias.rs index fbb1d8cc..e70105f3 100644 --- a/src/api/client_server/alias.rs +++ b/src/api/client_server/alias.rs @@ -8,7 +8,7 @@ use ruma::{ }, federation, }, - OwnedRoomAliasId, OwnedRoomId, OwnedServerName, + OwnedRoomAliasId, OwnedServerName, RoomAliasId, RoomId, }; use tracing::debug; @@ -219,7 +219,7 @@ pub async fn get_alias_helper( } fn room_available_servers( - room_id: &OwnedRoomId, room_alias: &OwnedRoomAliasId, pre_servers: &Option>, + room_id: &RoomId, room_alias: &RoomAliasId, pre_servers: &Option>, ) -> Vec { // find active servers in room state cache to suggest let mut servers: Vec = services() @@ -260,7 +260,7 @@ fn room_available_servers( servers } -async fn alias_checks(room_alias: &OwnedRoomAliasId, appservice_info: &Option) -> Result<()> { +async fn alias_checks(room_alias: &RoomAliasId, appservice_info: &Option) -> Result<()> { if !server_is_ours(room_alias.server_name()) { return Err(Error::BadRequest(ErrorKind::InvalidParam, "Alias is from another server.")); } diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index cb8930ec..2c27f569 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -886,7 +886,7 @@ fn default_power_levels_content( /// if a room is being created with a room alias, run our checks async fn room_alias_check( - room_alias_name: &String, appservice_info: &Option, + room_alias_name: &str, appservice_info: &Option, ) -> Result { // Basic checks on the room alias validity if room_alias_name.contains(':') { @@ -944,7 +944,7 @@ async fn room_alias_check( } /// if a room is being created with a custom room ID, run our checks against it -fn custom_room_id_check(custom_room_id: &String) -> Result { +fn custom_room_id_check(custom_room_id: &str) -> Result { // apply forbidden room alias checks to custom room IDs too if services() .globals diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 933f7b58..8a83cbe7 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -492,7 +492,7 @@ async fn handle_left_room( } async fn process_presence_updates( - presence_updates: &mut HashMap, since: u64, syncing_user: &OwnedUserId, + presence_updates: &mut HashMap, since: u64, syncing_user: &UserId, ) -> Result<()> { use crate::service::presence::Presence; diff --git a/src/service/admin.rs b/src/service/admin.rs index f38c75c4..19923d0a 100644 --- a/src/service/admin.rs +++ b/src/service/admin.rs @@ -111,9 +111,9 @@ impl Service { .await; } - async fn receive(&self, event: AdminRoomEvent, room: &OwnedRoomId, user: &UserId) -> Result<(), Error> { + async fn receive(&self, event: AdminRoomEvent, room: &RoomId, user: &UserId) -> Result<(), Error> { if let Some(handle) = self.handle.lock().await.as_ref() { - handle(event, room.clone(), user.into()).await + handle(event, room.into(), user.into()).await } else { Err(Error::Err("Admin module is not loaded.".into())) } diff --git a/src/service/sending/sender.rs b/src/service/sending/sender.rs index 9e107df8..c4de3e60 100644 --- a/src/service/sending/sender.rs +++ b/src/service/sending/sender.rs @@ -406,7 +406,7 @@ async fn send_events(dest: Destination, events: Vec) -> SendingRes } #[tracing::instrument(skip(dest, events))] -async fn send_events_dest_appservice(dest: &Destination, id: &String, events: Vec) -> SendingResult { +async fn send_events_dest_appservice(dest: &Destination, id: &str, events: Vec) -> SendingResult { let mut pdu_jsons = Vec::new(); for event in &events { @@ -469,7 +469,7 @@ async fn send_events_dest_appservice(dest: &Destination, id: &String, events: Ve #[tracing::instrument(skip(dest, events))] async fn send_events_dest_push( - dest: &Destination, userid: &OwnedUserId, pushkey: &String, events: Vec, + dest: &Destination, userid: &OwnedUserId, pushkey: &str, events: Vec, ) -> SendingResult { let mut pdus = Vec::new();