Make Event trait Send+Sync.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-07-08 11:50:54 +00:00
parent b0315da3d7
commit 8244d78cb2
15 changed files with 27 additions and 25 deletions

View File

@@ -256,7 +256,7 @@ pub(crate) async fn is_ignored_pdu<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.

View File

@@ -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<T>(self) -> T

View File

@@ -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<Item = &EventId> + 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<Item = &EventId> + Clone + Send + '_ {
self.auth_events.iter().map(AsRef::as_ref)

View File

@@ -349,9 +349,9 @@ impl Service {
Ok(())
}
pub async fn is_admin_command<E>(&self, event: &E, body: &str) -> bool
pub async fn is_admin_command<Pdu>(&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('\\');

View File

@@ -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<E>(
async fn send_notice<Pdu: Event>(
&self,
unread: UInt,
pusher: &Pusher,
tweaks: Vec<Tweak>,
event: &E,
event: &Pdu,
) -> Result
where
E: Event + Send + Sync,
{
// TODO: email
match &pusher.kind {

View File

@@ -38,7 +38,7 @@ pub(super) async fn fetch_and_handle_outliers<'a, Pdu, Events>(
room_id: &'a RoomId,
) -> Vec<(PduEvent, Option<BTreeMap<String, CanonicalJsonValue>>)>
where
Pdu: Event + Send + Sync,
Pdu: Event,
Events: Iterator<Item = &'a EventId> + Clone + Send,
{
let back_off = |id| match self

View File

@@ -35,7 +35,7 @@ pub(super) async fn fetch_prev<'a, Pdu, Events>(
HashMap<OwnedEventId, (PduEvent, BTreeMap<String, CanonicalJsonValue>)>,
)>
where
Pdu: Event + Send + Sync,
Pdu: Event,
Events: Iterator<Item = &'a EventId> + Clone + Send,
{
let num_ids = initial_set.clone().count();

View File

@@ -26,7 +26,7 @@ pub(super) async fn fetch_state<Pdu>(
event_id: &EventId,
) -> Result<Option<HashMap<u64, OwnedEventId>>>
where
Pdu: Event + Send + Sync,
Pdu: Event,
{
let res = self
.services

View File

@@ -24,7 +24,7 @@ pub(super) async fn handle_outlier_pdu<'a, Pdu>(
auth_events_known: bool,
) -> Result<(PduEvent, BTreeMap<String, CanonicalJsonValue>)>
where
Pdu: Event + Send + Sync,
Pdu: Event,
{
// 1. Remove unsigned field
value.remove("unsigned");

View File

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

View File

@@ -24,7 +24,7 @@ pub(super) async fn state_at_incoming_degree_one<Pdu>(
incoming_pdu: &Pdu,
) -> Result<Option<HashMap<u64, OwnedEventId>>>
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<Pdu>(
room_version_id: &RoomVersionId,
) -> Result<Option<HashMap<u64, OwnedEventId>>>
where
Pdu: Event + Send + Sync,
Pdu: Event,
{
trace!("Calculating extremity statehashes...");
let Ok(extremity_sstatehashes) = incoming_pdu

View File

@@ -26,7 +26,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu<Pdu>(
room_id: &RoomId,
) -> Result<Option<RawPduId>>
where
Pdu: Event + Send + Sync,
Pdu: Event,
{
// Skip the PDU if we already have it as a timeline event
if let Ok(pduid) = self

View File

@@ -332,10 +332,9 @@ impl Service {
}
#[tracing::instrument(skip_all, level = "debug")]
pub async fn summary_stripped<'a, E>(&self, event: &'a E) -> Vec<Raw<AnyStrippedStateEvent>>
pub async fn summary_stripped<Pdu>(&self, event: &Pdu) -> Vec<Raw<AnyStrippedStateEvent>>
where
E: Event + Send + Sync,
&'a E: Event + Send,
Pdu: Event,
{
let cells = [
(&StateEventType::RoomCreate, ""),

View File

@@ -51,7 +51,7 @@ impl crate::Service for Service {
impl Service {
pub async fn add_to_thread<E>(&self, root_event_id: &EventId, event: &E) -> Result
where
E: Event + Send + Sync,
E: Event,
{
let root_id = self
.services

View File

@@ -168,7 +168,7 @@ pub async fn build_and_append_pdu(
#[tracing::instrument(skip_all, level = "debug")]
async fn check_pdu_for_admin_room<Pdu>(&self, pdu: &Pdu, sender: &UserId) -> Result
where
Pdu: Event + Send + Sync,
Pdu: Event,
{
match pdu.kind() {
| TimelineEventType::RoomEncryption => {