diff --git a/testing/matrix-sdk-test/src/sync_builder/joined_room.rs b/testing/matrix-sdk-test/src/sync_builder/joined_room.rs index e1f0db222..ea8ee29a9 100644 --- a/testing/matrix-sdk-test/src/sync_builder/joined_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/joined_room.rs @@ -8,7 +8,7 @@ use ruma::{ }; use serde_json::{from_value as from_json_value, Value as JsonValue}; -use super::{EphemeralTestEvent, RoomAccountDataTestEvent, StateTestEvent, TimelineTestEvent}; +use super::{EphemeralTestEvent, RoomAccountDataTestEvent, StateTestEvent}; use crate::test_json; pub struct JoinedRoomBuilder { @@ -26,8 +26,13 @@ impl JoinedRoomBuilder { } /// Add an event to the timeline. - pub fn add_timeline_event(mut self, event: TimelineTestEvent) -> Self { - self.inner.timeline.events.push(event.into_raw_event()); + /// + /// [`TimelineTestEvent`][super::TimelineTestEvent] can be passed because it + /// implements `Into`. The raw event can also be + /// created with the [`sync_timeline_event`](crate::sync_timeline_event) + /// macro. + pub fn add_timeline_event(mut self, event: impl Into>) -> Self { + self.inner.timeline.events.push(event.into()); self } diff --git a/testing/matrix-sdk-test/src/sync_builder/left_room.rs b/testing/matrix-sdk-test/src/sync_builder/left_room.rs index 54bda9595..08c32afa0 100644 --- a/testing/matrix-sdk-test/src/sync_builder/left_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/left_room.rs @@ -5,7 +5,7 @@ use ruma::{ OwnedRoomId, }; -use super::{RoomAccountDataTestEvent, StateTestEvent, TimelineTestEvent}; +use super::{RoomAccountDataTestEvent, StateTestEvent}; use crate::test_json; pub struct LeftRoomBuilder { @@ -23,8 +23,13 @@ impl LeftRoomBuilder { } /// Add an event to the timeline. - pub fn add_timeline_event(mut self, event: TimelineTestEvent) -> Self { - self.inner.timeline.events.push(event.into_raw_event()); + /// + /// [`TimelineTestEvent`][super::TimelineTestEvent] can be passed because it + /// implements `Into`. The raw event can also be + /// created with the [`sync_timeline_event`](crate::sync_timeline_event) + /// macro. + pub fn add_timeline_event(mut self, event: impl Into>) -> Self { + self.inner.timeline.events.push(event.into()); self } diff --git a/testing/matrix-sdk-test/src/sync_builder/test_event.rs b/testing/matrix-sdk-test/src/sync_builder/test_event.rs index 79499b462..958a21726 100644 --- a/testing/matrix-sdk-test/src/sync_builder/test_event.rs +++ b/testing/matrix-sdk-test/src/sync_builder/test_event.rs @@ -67,10 +67,12 @@ impl TimelineTestEvent { Self::Custom(json) => json, } } +} +impl From for Raw { /// Get the typed JSON representation of this test event. - pub fn into_raw_event(self) -> Raw { - from_json_value(self.into_json_value()).unwrap() + fn from(value: TimelineTestEvent) -> Self { + from_json_value(value.into_json_value()).unwrap() } }