From 8244d78cb24179e21083d07e47b7b130be037352 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 8 Jul 2025 11:50:54 +0000 Subject: [PATCH] Make Event trait Send+Sync. Signed-off-by: Jason Volk --- src/api/client/message.rs | 2 +- src/core/matrix/event.rs | 2 +- src/core/matrix/pdu.rs | 10 ++++++++-- src/service/admin/mod.rs | 4 ++-- src/service/pusher/mod.rs | 9 +++------ .../rooms/event_handler/fetch_and_handle_outliers.rs | 2 +- src/service/rooms/event_handler/fetch_prev.rs | 2 +- src/service/rooms/event_handler/fetch_state.rs | 2 +- src/service/rooms/event_handler/handle_outlier_pdu.rs | 2 +- src/service/rooms/event_handler/handle_prev_pdu.rs | 2 +- src/service/rooms/event_handler/state_at_incoming.rs | 4 ++-- src/service/rooms/event_handler/upgrade_outlier_pdu.rs | 2 +- src/service/rooms/state/mod.rs | 5 ++--- src/service/rooms/threads/mod.rs | 2 +- src/service/rooms/timeline/build.rs | 2 +- 15 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/api/client/message.rs b/src/api/client/message.rs index 85f038e7..ffbcc5ef 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -256,7 +256,7 @@ pub(crate) async fn is_ignored_pdu( user_id: &UserId, ) -> bool where - Pdu: Event + Send + Sync, + Pdu: Event, { // exclude Synapse's dummy events from bloating up response bodies. clients // don't need to see this. diff --git a/src/core/matrix/event.rs b/src/core/matrix/event.rs index a1d1339e..35a79966 100644 --- a/src/core/matrix/event.rs +++ b/src/core/matrix/event.rs @@ -21,7 +21,7 @@ use super::{pdu::Pdu, state_key::StateKey}; use crate::{Result, utils}; /// Abstraction of a PDU so users can have their own PDU types. -pub trait Event: Clone + Debug { +pub trait Event: Clone + Debug + Send + Sync { /// Serialize into a Ruma JSON format, consuming. #[inline] fn into_format(self) -> T diff --git a/src/core/matrix/pdu.rs b/src/core/matrix/pdu.rs index bff0c203..cce9e286 100644 --- a/src/core/matrix/pdu.rs +++ b/src/core/matrix/pdu.rs @@ -84,7 +84,10 @@ impl Pdu { } } -impl Event for Pdu { +impl Event for Pdu +where + Self: Send + Sync + 'static, +{ #[inline] fn auth_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_ { self.auth_events.iter().map(AsRef::as_ref) @@ -137,7 +140,10 @@ impl Event for Pdu { fn is_owned(&self) -> bool { true } } -impl Event for &Pdu { +impl Event for &Pdu +where + Self: Send, +{ #[inline] fn auth_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_ { self.auth_events.iter().map(AsRef::as_ref) diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 698e169a..67218c8b 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -349,9 +349,9 @@ impl Service { Ok(()) } - pub async fn is_admin_command(&self, event: &E, body: &str) -> bool + pub async fn is_admin_command(&self, event: &Pdu, body: &str) -> bool where - E: Event + Send + Sync, + Pdu: Event, { // Server-side command-escape with public echo let is_escape = body.starts_with('\\'); diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 989210c1..2d942efd 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -296,8 +296,7 @@ impl Service { event: &E, ) -> Result where - E: Event + Send + Sync, - for<'a> &'a E: Event + Send, + E: Event, { let mut notify = None; let mut tweaks = Vec::new(); @@ -385,15 +384,13 @@ impl Service { } #[tracing::instrument(skip(self, unread, pusher, tweaks, event))] - async fn send_notice( + async fn send_notice( &self, unread: UInt, pusher: &Pusher, tweaks: Vec, - event: &E, + event: &Pdu, ) -> Result - where - E: Event + Send + Sync, { // TODO: email match &pusher.kind { diff --git a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs index 714ede22..f4fe5fb7 100644 --- a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs +++ b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs @@ -38,7 +38,7 @@ pub(super) async fn fetch_and_handle_outliers<'a, Pdu, Events>( room_id: &'a RoomId, ) -> Vec<(PduEvent, Option>)> where - Pdu: Event + Send + Sync, + Pdu: Event, Events: Iterator + Clone + Send, { let back_off = |id| match self diff --git a/src/service/rooms/event_handler/fetch_prev.rs b/src/service/rooms/event_handler/fetch_prev.rs index 5f469605..ee6956fa 100644 --- a/src/service/rooms/event_handler/fetch_prev.rs +++ b/src/service/rooms/event_handler/fetch_prev.rs @@ -35,7 +35,7 @@ pub(super) async fn fetch_prev<'a, Pdu, Events>( HashMap)>, )> where - Pdu: Event + Send + Sync, + Pdu: Event, Events: Iterator + Clone + Send, { let num_ids = initial_set.clone().count(); diff --git a/src/service/rooms/event_handler/fetch_state.rs b/src/service/rooms/event_handler/fetch_state.rs index 329ad9f1..82591631 100644 --- a/src/service/rooms/event_handler/fetch_state.rs +++ b/src/service/rooms/event_handler/fetch_state.rs @@ -26,7 +26,7 @@ pub(super) async fn fetch_state( event_id: &EventId, ) -> Result>> where - Pdu: Event + Send + Sync, + Pdu: Event, { let res = self .services diff --git a/src/service/rooms/event_handler/handle_outlier_pdu.rs b/src/service/rooms/event_handler/handle_outlier_pdu.rs index 5b0261a1..d84df8f1 100644 --- a/src/service/rooms/event_handler/handle_outlier_pdu.rs +++ b/src/service/rooms/event_handler/handle_outlier_pdu.rs @@ -24,7 +24,7 @@ pub(super) async fn handle_outlier_pdu<'a, Pdu>( auth_events_known: bool, ) -> Result<(PduEvent, BTreeMap)> where - Pdu: Event + Send + Sync, + Pdu: Event, { // 1. Remove unsigned field value.remove("unsigned"); diff --git a/src/service/rooms/event_handler/handle_prev_pdu.rs b/src/service/rooms/event_handler/handle_prev_pdu.rs index 1cd6df6a..59f536a0 100644 --- a/src/service/rooms/event_handler/handle_prev_pdu.rs +++ b/src/service/rooms/event_handler/handle_prev_pdu.rs @@ -29,7 +29,7 @@ pub(super) async fn handle_prev_pdu<'a, Pdu>( prev_id: &'a EventId, ) -> Result where - Pdu: Event + Send + Sync, + Pdu: Event, { // Check for disabled again because it might have changed if self.services.metadata.is_disabled(room_id).await { diff --git a/src/service/rooms/event_handler/state_at_incoming.rs b/src/service/rooms/event_handler/state_at_incoming.rs index 0542c70b..a671f1f1 100644 --- a/src/service/rooms/event_handler/state_at_incoming.rs +++ b/src/service/rooms/event_handler/state_at_incoming.rs @@ -24,7 +24,7 @@ pub(super) async fn state_at_incoming_degree_one( incoming_pdu: &Pdu, ) -> Result>> where - Pdu: Event + Send + Sync, + Pdu: Event, { let prev_event = incoming_pdu .prev_events() @@ -80,7 +80,7 @@ pub(super) async fn state_at_incoming_resolved( room_version_id: &RoomVersionId, ) -> Result>> where - Pdu: Event + Send + Sync, + Pdu: Event, { trace!("Calculating extremity statehashes..."); let Ok(extremity_sstatehashes) = incoming_pdu diff --git a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs index 1dbe2619..4db8a0b3 100644 --- a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs +++ b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs @@ -26,7 +26,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( room_id: &RoomId, ) -> Result> where - Pdu: Event + Send + Sync, + Pdu: Event, { // Skip the PDU if we already have it as a timeline event if let Ok(pduid) = self diff --git a/src/service/rooms/state/mod.rs b/src/service/rooms/state/mod.rs index 9f1bfd2d..fef12ed5 100644 --- a/src/service/rooms/state/mod.rs +++ b/src/service/rooms/state/mod.rs @@ -332,10 +332,9 @@ impl Service { } #[tracing::instrument(skip_all, level = "debug")] - pub async fn summary_stripped<'a, E>(&self, event: &'a E) -> Vec> + pub async fn summary_stripped(&self, event: &Pdu) -> Vec> where - E: Event + Send + Sync, - &'a E: Event + Send, + Pdu: Event, { let cells = [ (&StateEventType::RoomCreate, ""), diff --git a/src/service/rooms/threads/mod.rs b/src/service/rooms/threads/mod.rs index 76526f51..3b942eb3 100644 --- a/src/service/rooms/threads/mod.rs +++ b/src/service/rooms/threads/mod.rs @@ -51,7 +51,7 @@ impl crate::Service for Service { impl Service { pub async fn add_to_thread(&self, root_event_id: &EventId, event: &E) -> Result where - E: Event + Send + Sync, + E: Event, { let root_id = self .services diff --git a/src/service/rooms/timeline/build.rs b/src/service/rooms/timeline/build.rs index 2cfd5e59..a30807ec 100644 --- a/src/service/rooms/timeline/build.rs +++ b/src/service/rooms/timeline/build.rs @@ -168,7 +168,7 @@ pub async fn build_and_append_pdu( #[tracing::instrument(skip_all, level = "debug")] async fn check_pdu_for_admin_room(&self, pdu: &Pdu, sender: &UserId) -> Result where - Pdu: Event + Send + Sync, + Pdu: Event, { match pdu.kind() { | TimelineEventType::RoomEncryption => {