Convert Pdu to a validated ruma type when calling to_*_event
This commit is contained in:
parent
75959cdc10
commit
9a993fa7c1
34
src/pdu.rs
34
src/pdu.rs
|
@ -79,34 +79,40 @@ impl PduEvent {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn to_room_event_stub(&self) -> EventJson<AnySyncRoomEvent> {
|
||||
pub fn to_sync_room_event(&self) -> EventJson<AnySyncRoomEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnySyncRoomEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
serde_json::from_str::<AnySyncRoomEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.expect("AnySyncRoomEvent can always be built from a full PDU event")
|
||||
}
|
||||
pub fn to_room_event(&self) -> EventJson<AnyRoomEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnyRoomEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
serde_json::from_str::<AnyRoomEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.expect("AnyRoomEvent can always be built from a full PDU event")
|
||||
}
|
||||
pub fn to_state_event(&self) -> EventJson<AnyStateEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnyStateEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
serde_json::from_str::<AnyStateEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.expect("AnyStateEvent can always be built from a full PDU event")
|
||||
}
|
||||
pub fn to_state_event_stub(&self) -> EventJson<AnySyncStateEvent> {
|
||||
pub fn to_sync_state_event(&self) -> EventJson<AnySyncStateEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnySyncStateEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
serde_json::from_str::<AnySyncStateEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.expect("AnySyncStateEvent can always be built from a full PDU event")
|
||||
}
|
||||
pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnyStrippedStateEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
serde_json::from_str::<AnyStrippedStateEvent>(&json)
|
||||
.map(EventJson::from)
|
||||
.expect("AnyStrippedStateEvent can always be built from a full PDU event")
|
||||
}
|
||||
pub fn to_member_event(&self) -> EventJson<StateEvent<MemberEventContent>> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<StateEvent<MemberEventContent>>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
serde_json::from_str::<StateEvent<MemberEventContent>>(&json)
|
||||
.map(EventJson::from)
|
||||
.expect("StateEvent<MemberEventContent> can always be built from a full PDU event")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue