This commit is contained in:
timokoesters 2020-04-19 14:14:47 +02:00
parent 4d658b3952
commit 80ddf80f17
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
10 changed files with 632 additions and 141 deletions

View file

@ -31,15 +31,18 @@ pub struct PduEvent {
}
impl PduEvent {
pub fn to_room_event(&self) -> RoomEvent {
// TODO: This shouldn't be an option
pub fn to_room_event(&self) -> Option<RoomEvent> {
// Can only fail in rare circumstances that won't ever happen here, see
// https://docs.rs/serde_json/1.0.50/serde_json/fn.to_string.html
let json = serde_json::to_string(&self).unwrap();
// EventResult's deserialize implementation always returns `Ok(...)`
serde_json::from_str::<EventResult<RoomEvent>>(&json)
.unwrap()
.into_result()
.unwrap()
Some(
serde_json::from_str::<EventResult<RoomEvent>>(&json)
.unwrap()
.into_result()
.ok()?,
)
}
pub fn to_stripped_state_event(&self) -> Option<AnyStrippedStateEvent> {