feat(sdk-test): Add conversions to deserialized types for EventBuilder
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Damir Jelić
parent
d85b45ed64
commit
2b69a7f741
@@ -32,10 +32,11 @@ use ruma::{
|
||||
AnyGlobalAccountDataEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent,
|
||||
AnySyncEphemeralRoomEvent, AnySyncMessageLikeEvent, AnySyncStateEvent,
|
||||
AnySyncTimelineEvent, AnyTimelineEvent, BundledMessageLikeRelations,
|
||||
EphemeralRoomEventContent, False, GlobalAccountDataEventContent, Mentions,
|
||||
MessageLikeEvent, MessageLikeEventContent, RedactContent, RedactedMessageLikeEventContent,
|
||||
RedactedStateEventContent, StateEvent, StateEventContent, StaticEventContent,
|
||||
StaticStateEventContent, StrippedStateEvent, SyncMessageLikeEvent, SyncStateEvent,
|
||||
EphemeralRoomEventContent, EventContentFromType, False, GlobalAccountDataEventContent,
|
||||
Mentions, MessageLikeEvent, MessageLikeEventContent, PossiblyRedactedStateEventContent,
|
||||
RedactContent, RedactedMessageLikeEventContent, RedactedStateEventContent, StateEvent,
|
||||
StateEventContent, StaticEventContent, StaticStateEventContent, StrippedStateEvent,
|
||||
SyncMessageLikeEvent, SyncStateEvent,
|
||||
beacon::BeaconEventContent,
|
||||
call::{SessionDescription, invite::CallInviteEventContent},
|
||||
direct::{DirectEventContent, OwnedDirectUserIdentifier},
|
||||
@@ -542,6 +543,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for AnySyncTimelineEvent
|
||||
where
|
||||
E: Serialize,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnySyncTimelineEvent>::from(val).deserialize().expect("expected sync timeline event")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for Raw<AnyTimelineEvent>
|
||||
where
|
||||
E: Serialize,
|
||||
@@ -551,6 +561,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for AnyTimelineEvent
|
||||
where
|
||||
E: Serialize,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnyTimelineEvent>::from(val).deserialize().expect("expected timeline event")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>>
|
||||
for Raw<AnyGlobalAccountDataEvent>
|
||||
where
|
||||
@@ -561,6 +580,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for AnyGlobalAccountDataEvent
|
||||
where
|
||||
E: Serialize,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnyGlobalAccountDataEvent>::from(val)
|
||||
.deserialize()
|
||||
.expect("expected global account data")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for TimelineEvent
|
||||
where
|
||||
E: Serialize,
|
||||
@@ -578,6 +608,14 @@ impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuil
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for AnySyncStateEvent
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnySyncStateEvent>::from(val).deserialize().expect("expected sync state")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for Raw<SyncStateEvent<E>>
|
||||
where
|
||||
@@ -589,6 +627,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for SyncStateEvent<E>
|
||||
where
|
||||
E: StaticStateEventContent + RedactContent + EventContentFromType,
|
||||
E::Redacted: RedactedStateEventContent<StateKey = <E as StateEventContent>::StateKey>
|
||||
+ EventContentFromType,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<SyncStateEvent<E>>::from(val).deserialize().expect("expected sync state")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for Raw<AnyStateEvent>
|
||||
{
|
||||
@@ -597,6 +647,14 @@ impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuil
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for AnyStateEvent
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnyStateEvent>::from(val).deserialize().expect("expected state")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for Raw<StateEvent<E>>
|
||||
where
|
||||
@@ -608,6 +666,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for StateEvent<E>
|
||||
where
|
||||
E: StaticStateEventContent + RedactContent + EventContentFromType,
|
||||
E::Redacted: RedactedStateEventContent<StateKey = <E as StateEventContent>::StateKey>
|
||||
+ EventContentFromType,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<StateEvent<E>>::from(val).deserialize().expect("expected state")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for Raw<AnyStrippedStateEvent>
|
||||
{
|
||||
@@ -616,6 +686,14 @@ impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuil
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for AnyStrippedStateEvent
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnyStrippedStateEvent>::from(val).deserialize().expect("expected stripped state")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for Raw<StrippedStateEvent<E::PossiblyRedacted>>
|
||||
where
|
||||
@@ -626,6 +704,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for StrippedStateEvent<E::PossiblyRedacted>
|
||||
where
|
||||
E: StaticStateEventContent,
|
||||
E::PossiblyRedacted: PossiblyRedactedStateEventContent + EventContentFromType,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<StrippedStateEvent<E::PossiblyRedacted>>::from(val)
|
||||
.deserialize()
|
||||
.expect("expected stripped state")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + EphemeralRoomEventContent> From<EventBuilder<E>>
|
||||
for Raw<AnySyncEphemeralRoomEvent>
|
||||
{
|
||||
@@ -634,6 +725,14 @@ impl<E: StaticEventContent<IsPrefix = False> + EphemeralRoomEventContent> From<E
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + EphemeralRoomEventContent> From<EventBuilder<E>>
|
||||
for AnySyncEphemeralRoomEvent
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnySyncEphemeralRoomEvent>::from(val).deserialize().expect("expected ephemeral")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for Raw<AnySyncMessageLikeEvent>
|
||||
{
|
||||
@@ -642,6 +741,14 @@ impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<Eve
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for AnySyncMessageLikeEvent
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnySyncMessageLikeEvent>::from(val).deserialize().expect("expected sync message-like")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for Raw<SyncMessageLikeEvent<E>>
|
||||
where
|
||||
@@ -653,6 +760,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for SyncMessageLikeEvent<E>
|
||||
where
|
||||
E: RedactContent + EventContentFromType,
|
||||
E::Redacted: RedactedMessageLikeEventContent + EventContentFromType,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<SyncMessageLikeEvent<E>>::from(val).deserialize().expect("expected sync message-like")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for Raw<AnyMessageLikeEvent>
|
||||
{
|
||||
@@ -661,6 +779,14 @@ impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<Eve
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for AnyMessageLikeEvent
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<AnyMessageLikeEvent>::from(val).deserialize().expect("expected message-like")
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for Raw<MessageLikeEvent<E>>
|
||||
where
|
||||
@@ -672,6 +798,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent<IsPrefix = False> + MessageLikeEventContent> From<EventBuilder<E>>
|
||||
for MessageLikeEvent<E>
|
||||
where
|
||||
E: RedactContent + EventContentFromType,
|
||||
E::Redacted: RedactedMessageLikeEventContent + EventContentFromType,
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::<MessageLikeEvent<E>>::from(val).deserialize().expect("expected message-like")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct EventFactory {
|
||||
next_ts: AtomicU64,
|
||||
|
||||
Reference in New Issue
Block a user