Remove FromStr, TryFrom<&'_ str> implementations
This commit is contained in:
parent
fbd8b2be54
commit
297bae4cbb
@ -1,8 +1,6 @@
|
||||
//! Enums for heterogeneous collections of events, inclusive for every event type that implements
|
||||
//! the trait of the same name.
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde_json::{from_value, Value};
|
||||
|
||||
@ -392,373 +390,6 @@ impl Serialize for Event {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Event {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let value: Value = serde_json::from_str(json)?;
|
||||
|
||||
let event_type_value = match value.get("type") {
|
||||
Some(value) => value.clone(),
|
||||
None => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "missing field `type`".to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
let event_type = match from_value::<EventType>(event_type_value.clone()) {
|
||||
Ok(event_type) => event_type,
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
match event_type {
|
||||
EventType::CallAnswer => match json.parse() {
|
||||
Ok(event) => Ok(Event::CallAnswer(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallCandidates => match json.parse() {
|
||||
Ok(event) => Ok(Event::CallCandidates(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallHangup => match json.parse() {
|
||||
Ok(event) => Ok(Event::CallHangup(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallInvite => match json.parse() {
|
||||
Ok(event) => Ok(Event::CallInvite(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Direct => match json.parse() {
|
||||
Ok(event) => Ok(Event::Direct(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Dummy => match json.parse() {
|
||||
Ok(event) => Ok(Event::Dummy(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::ForwardedRoomKey => match json.parse() {
|
||||
Ok(event) => Ok(Event::ForwardedRoomKey(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::FullyRead => match json.parse() {
|
||||
Ok(event) => Ok(Event::FullyRead(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationAccept => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationAccept(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationCancel => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationCancel(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationKey => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationKey(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationMac => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationMac(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationRequest => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationRequest(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationStart => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationStart(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::IgnoredUserList => match json.parse() {
|
||||
Ok(event) => Ok(Event::IgnoredUserList(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Presence => match json.parse() {
|
||||
Ok(event) => Ok(Event::Presence(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::PushRules => match json.parse() {
|
||||
Ok(event) => Ok(Event::PushRules(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Receipt => match json.parse() {
|
||||
Ok(event) => Ok(Event::Receipt(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomAliases => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomAliases(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomAvatar => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomAvatar(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomCanonicalAlias => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomCanonicalAlias(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomCreate => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomCreate(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomEncrypted => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomEncrypted(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomEncryption => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomEncryption(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomGuestAccess => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomGuestAccess(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomHistoryVisibility => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomHistoryVisibility(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomJoinRules => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomJoinRules(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMember => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomMember(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMessage => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomMessage(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMessageFeedback => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomMessageFeedback(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomName => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomName(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomPinnedEvents => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomPinnedEvents(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomPowerLevels => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomPowerLevels(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomRedaction => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomRedaction(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomServerAcl => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomServerAcl(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomThirdPartyInvite => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomThirdPartyInvite(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomTombstone => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomTombstone(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomTopic => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomTopic(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomKey => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomKey(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomKeyRequest => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomKeyRequest(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Sticker => match json.parse() {
|
||||
Ok(event) => Ok(Event::Sticker(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Tag => match json.parse() {
|
||||
Ok(event) => Ok(Event::Tag(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Typing => match json.parse() {
|
||||
Ok(event) => Ok(Event::Typing(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Custom(_) => {
|
||||
if value.get("state_key").is_some() {
|
||||
match json.parse() {
|
||||
Ok(event) => Ok(Event::CustomState(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
}
|
||||
} else if value.get("event_id").is_some()
|
||||
&& value.get("room_id").is_some()
|
||||
&& value.get("sender").is_some()
|
||||
{
|
||||
match json.parse() {
|
||||
Ok(event) => Ok(Event::CustomRoom(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
}
|
||||
} else {
|
||||
match json.parse() {
|
||||
Ok(event) => Ok(Event::Custom(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
EventType::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for RoomEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -796,257 +427,6 @@ impl Serialize for RoomEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for RoomEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let value: Value = serde_json::from_str(json)?;
|
||||
|
||||
let event_type_value = match value.get("type") {
|
||||
Some(value) => value.clone(),
|
||||
None => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "missing field `type`".to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
let event_type = match from_value::<EventType>(event_type_value.clone()) {
|
||||
Ok(event_type) => event_type,
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
match event_type {
|
||||
EventType::CallAnswer => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallAnswer(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallCandidates => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallCandidates(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallHangup => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallHangup(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallInvite => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallInvite(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomAliases => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomAliases(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomAvatar => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomAvatar(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomCanonicalAlias => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomCanonicalAlias(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomCreate => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomCreate(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomEncrypted => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomEncrypted(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomEncryption => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomEncryption(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomGuestAccess => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomGuestAccess(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomHistoryVisibility => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomHistoryVisibility(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomJoinRules => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomJoinRules(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMember => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomMember(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMessage => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomMessage(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMessageFeedback => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomMessageFeedback(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomName => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomName(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomPinnedEvents => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomPinnedEvents(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomPowerLevels => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomPowerLevels(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomRedaction => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomRedaction(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomServerAcl => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomServerAcl(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomThirdPartyInvite => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomThirdPartyInvite(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomTombstone => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomTombstone(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomTopic => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomTopic(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Sticker => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::Sticker(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Custom(_) => {
|
||||
if value.get("state_key").is_some() {
|
||||
match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CustomState(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
}
|
||||
} else {
|
||||
match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CustomRoom(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
EventType::Direct
|
||||
| EventType::Dummy
|
||||
| EventType::ForwardedRoomKey
|
||||
| EventType::FullyRead
|
||||
| EventType::KeyVerificationAccept
|
||||
| EventType::KeyVerificationCancel
|
||||
| EventType::KeyVerificationKey
|
||||
| EventType::KeyVerificationMac
|
||||
| EventType::KeyVerificationRequest
|
||||
| EventType::KeyVerificationStart
|
||||
| EventType::IgnoredUserList
|
||||
| EventType::Presence
|
||||
| EventType::PushRules
|
||||
| EventType::Receipt
|
||||
| EventType::RoomKey
|
||||
| EventType::RoomKeyRequest
|
||||
| EventType::Tag
|
||||
| EventType::Typing => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "not a room event".to_string(),
|
||||
})),
|
||||
EventType::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for StateEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -1074,190 +454,6 @@ impl Serialize for StateEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for StateEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let value: Value = serde_json::from_str(json)?;
|
||||
|
||||
let event_type_value = match value.get("type") {
|
||||
Some(value) => value.clone(),
|
||||
None => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "missing field `type`".to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
let event_type = match from_value::<EventType>(event_type_value.clone()) {
|
||||
Ok(event_type) => event_type,
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
match event_type {
|
||||
EventType::RoomAliases => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomAliases(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomAvatar => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomAvatar(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomCanonicalAlias => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomCanonicalAlias(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomCreate => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomCreate(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomEncryption => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomEncryption(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomGuestAccess => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomGuestAccess(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomHistoryVisibility => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomHistoryVisibility(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomJoinRules => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomJoinRules(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMember => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomMember(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomName => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomName(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomPinnedEvents => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomPinnedEvents(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomPowerLevels => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomPowerLevels(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomServerAcl => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomServerAcl(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomThirdPartyInvite => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomThirdPartyInvite(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomTombstone => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomTombstone(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomTopic => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::RoomTopic(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Custom(_) => match json.parse() {
|
||||
Ok(event) => Ok(StateEvent::CustomState(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallAnswer
|
||||
| EventType::CallCandidates
|
||||
| EventType::CallHangup
|
||||
| EventType::CallInvite
|
||||
| EventType::Direct
|
||||
| EventType::Dummy
|
||||
| EventType::ForwardedRoomKey
|
||||
| EventType::FullyRead
|
||||
| EventType::KeyVerificationAccept
|
||||
| EventType::KeyVerificationCancel
|
||||
| EventType::KeyVerificationKey
|
||||
| EventType::KeyVerificationMac
|
||||
| EventType::KeyVerificationRequest
|
||||
| EventType::KeyVerificationStart
|
||||
| EventType::IgnoredUserList
|
||||
| EventType::Presence
|
||||
| EventType::PushRules
|
||||
| EventType::Receipt
|
||||
| EventType::RoomEncrypted
|
||||
| EventType::RoomMessage
|
||||
| EventType::RoomMessageFeedback
|
||||
| EventType::RoomRedaction
|
||||
| EventType::RoomKey
|
||||
| EventType::RoomKeyRequest
|
||||
| EventType::Sticker
|
||||
| EventType::Tag
|
||||
| EventType::Typing => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "not a state event".to_string(),
|
||||
})),
|
||||
EventType::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_from_t_for_event {
|
||||
($ty:ty, $variant:ident) => {
|
||||
impl From<$ty> for Event {
|
||||
|
@ -162,202 +162,6 @@ impl Serialize for Event {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Event {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let value: Value = serde_json::from_str(json)?;
|
||||
|
||||
let event_type_value = match value.get("type") {
|
||||
Some(value) => value.clone(),
|
||||
None => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "missing field `type`".to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
let event_type = match from_value::<EventType>(event_type_value.clone()) {
|
||||
Ok(event_type) => event_type,
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
match event_type {
|
||||
EventType::Direct => match json.parse() {
|
||||
Ok(event) => Ok(Event::Direct(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Dummy => match json.parse() {
|
||||
Ok(event) => Ok(Event::Dummy(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::ForwardedRoomKey => match json.parse() {
|
||||
Ok(event) => Ok(Event::ForwardedRoomKey(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::FullyRead => match json.parse() {
|
||||
Ok(event) => Ok(Event::FullyRead(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationAccept => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationAccept(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationCancel => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationCancel(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationKey => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationKey(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationMac => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationMac(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationRequest => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationRequest(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::KeyVerificationStart => match json.parse() {
|
||||
Ok(event) => Ok(Event::KeyVerificationStart(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::IgnoredUserList => match json.parse() {
|
||||
Ok(event) => Ok(Event::IgnoredUserList(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Presence => match json.parse() {
|
||||
Ok(event) => Ok(Event::Presence(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::PushRules => match json.parse() {
|
||||
Ok(event) => Ok(Event::PushRules(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Receipt => match json.parse() {
|
||||
Ok(event) => Ok(Event::Receipt(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomKey => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomKey(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomKeyRequest => match json.parse() {
|
||||
Ok(event) => Ok(Event::RoomKeyRequest(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Tag => match json.parse() {
|
||||
Ok(event) => Ok(Event::Tag(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Typing => match json.parse() {
|
||||
Ok(event) => Ok(Event::Typing(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Custom(_) => match json.parse() {
|
||||
Ok(event) => Ok(Event::Custom(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallAnswer
|
||||
| EventType::CallCandidates
|
||||
| EventType::CallHangup
|
||||
| EventType::CallInvite
|
||||
| EventType::RoomAliases
|
||||
| EventType::RoomAvatar
|
||||
| EventType::RoomCanonicalAlias
|
||||
| EventType::RoomCreate
|
||||
| EventType::RoomEncrypted
|
||||
| EventType::RoomEncryption
|
||||
| EventType::RoomGuestAccess
|
||||
| EventType::RoomHistoryVisibility
|
||||
| EventType::RoomJoinRules
|
||||
| EventType::RoomMember
|
||||
| EventType::RoomMessage
|
||||
| EventType::RoomMessageFeedback
|
||||
| EventType::RoomName
|
||||
| EventType::RoomPinnedEvents
|
||||
| EventType::RoomPowerLevels
|
||||
| EventType::RoomRedaction
|
||||
| EventType::RoomServerAcl
|
||||
| EventType::RoomThirdPartyInvite
|
||||
| EventType::RoomTombstone
|
||||
| EventType::RoomTopic
|
||||
| EventType::Sticker => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "not exclusively a basic event".to_string(),
|
||||
})),
|
||||
EventType::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for RoomEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -378,147 +182,6 @@ impl Serialize for RoomEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for RoomEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let value: Value = serde_json::from_str(json)?;
|
||||
|
||||
let event_type_value = match value.get("type") {
|
||||
Some(value) => value.clone(),
|
||||
None => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "missing field `type`".to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
let event_type = match from_value::<EventType>(event_type_value.clone()) {
|
||||
Ok(event_type) => event_type,
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
match event_type {
|
||||
EventType::CallAnswer => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallAnswer(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallCandidates => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallCandidates(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallHangup => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallHangup(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::CallInvite => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CallInvite(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomEncrypted => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomEncrypted(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMessage => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomMessage(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomMessageFeedback => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomMessageFeedback(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::RoomRedaction => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::RoomRedaction(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Sticker => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::Sticker(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Custom(_) => match json.parse() {
|
||||
Ok(event) => Ok(RoomEvent::CustomRoom(event)),
|
||||
Err(error) => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
})),
|
||||
},
|
||||
EventType::Direct
|
||||
| EventType::Dummy
|
||||
| EventType::ForwardedRoomKey
|
||||
| EventType::FullyRead
|
||||
| EventType::KeyVerificationAccept
|
||||
| EventType::KeyVerificationCancel
|
||||
| EventType::KeyVerificationKey
|
||||
| EventType::KeyVerificationMac
|
||||
| EventType::KeyVerificationRequest
|
||||
| EventType::KeyVerificationStart
|
||||
| EventType::IgnoredUserList
|
||||
| EventType::Presence
|
||||
| EventType::PushRules
|
||||
| EventType::Receipt
|
||||
| EventType::RoomAliases
|
||||
| EventType::RoomAvatar
|
||||
| EventType::RoomCanonicalAlias
|
||||
| EventType::RoomCreate
|
||||
| EventType::RoomEncryption
|
||||
| EventType::RoomGuestAccess
|
||||
| EventType::RoomHistoryVisibility
|
||||
| EventType::RoomJoinRules
|
||||
| EventType::RoomMember
|
||||
| EventType::RoomName
|
||||
| EventType::RoomPinnedEvents
|
||||
| EventType::RoomPowerLevels
|
||||
| EventType::RoomServerAcl
|
||||
| EventType::RoomThirdPartyInvite
|
||||
| EventType::RoomTombstone
|
||||
| EventType::RoomTopic
|
||||
| EventType::RoomKey
|
||||
| EventType::RoomKeyRequest
|
||||
| EventType::Tag
|
||||
| EventType::Typing => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: "not exclusively a room event".to_string(),
|
||||
})),
|
||||
EventType::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
macro_rules! impl_from_t_for_event {
|
||||
($ty:ty, $variant:ident) => {
|
||||
impl From<$ty> for Event {
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.ignored_user_list* event.
|
||||
|
||||
use std::{collections::HashMap, convert::TryFrom, str::FromStr};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ruma_identifiers::UserId;
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
@ -48,43 +48,6 @@ impl<'de> Deserialize<'de> for EventResult<IgnoredUserListEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for IgnoredUserListEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, InvalidEvent> {
|
||||
let raw = match serde_json::from_str::<raw::IgnoredUserListEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
content: IgnoredUserListEventContent {
|
||||
ignored_users: raw.content.ignored_users.keys().cloned().collect(),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for IgnoredUserListEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for IgnoredUserListEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -130,41 +93,6 @@ impl<'de> Deserialize<'de> for EventResult<IgnoredUserListEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for IgnoredUserListEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::IgnoredUserListEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
ignored_users: raw.ignored_users.keys().cloned().collect(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for IgnoredUserListEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for IgnoredUserListEventContent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! Types for the *m.key.verification.start* event.
|
||||
|
||||
use std::{convert::TryFrom, str::FromStr};
|
||||
|
||||
use ruma_identifiers::DeviceId;
|
||||
use serde::{de::Error, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_json::{from_value, Value};
|
||||
@ -68,46 +66,6 @@ impl<'de> Deserialize<'de> for EventResult<StartEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for StartEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::StartEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let content = match raw.content {
|
||||
raw::StartEventContent::MSasV1(content) => StartEventContent::MSasV1(content),
|
||||
raw::StartEventContent::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.");
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Self { content })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for StartEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for StartEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -197,84 +155,6 @@ impl<'de> Deserialize<'de> for EventResult<StartEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for StartEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::StartEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
match raw {
|
||||
raw::StartEventContent::MSasV1(content) => {
|
||||
if !content
|
||||
.key_agreement_protocols
|
||||
.contains(&KeyAgreementProtocol::Curve25519)
|
||||
{
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: serde_json::from_str::<Value>(json)?,
|
||||
message: "`key_agreement_protocols` must contain at least `KeyAgreementProtocol::Curve25519`".to_string(),
|
||||
}));
|
||||
}
|
||||
|
||||
if !content.hashes.contains(&HashAlgorithm::Sha256) {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: serde_json::from_str::<Value>(json)?,
|
||||
message: "`hashes` must contain at least `HashAlgorithm::Sha256`"
|
||||
.to_string(),
|
||||
}));
|
||||
}
|
||||
|
||||
if !content
|
||||
.message_authentication_codes
|
||||
.contains(&MessageAuthenticationCode::HkdfHmacSha256)
|
||||
{
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: serde_json::from_str::<Value>(json)?,
|
||||
message: "`message_authentication_codes` must contain at least `MessageAuthenticationCode::HkdfHmacSha256`".to_string(),
|
||||
}));
|
||||
}
|
||||
|
||||
if !content
|
||||
.short_authentication_string
|
||||
.contains(&ShortAuthenticationString::Decimal)
|
||||
{
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: serde_json::from_str::<Value>(json)?,
|
||||
message: "`short_authentication_string` must contain at least `ShortAuthenticationString::Decimal`".to_string(),
|
||||
}));
|
||||
}
|
||||
|
||||
Ok(StartEventContent::MSasV1(content))
|
||||
}
|
||||
raw::StartEventContent::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for StartEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for StartEventContent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! Types for the *m.room.canonical_alias* event.
|
||||
|
||||
use std::{convert::TryFrom, str::FromStr};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
@ -86,52 +84,6 @@ impl<'de> Deserialize<'de> for EventResult<CanonicalAliasEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for CanonicalAliasEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::CanonicalAliasEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
content: CanonicalAliasEventContent {
|
||||
alias: raw.content.alias,
|
||||
},
|
||||
event_id: raw.event_id,
|
||||
origin_server_ts: raw.origin_server_ts,
|
||||
prev_content: raw
|
||||
.prev_content
|
||||
.map(|prev| CanonicalAliasEventContent { alias: prev.alias }),
|
||||
room_id: raw.room_id,
|
||||
sender: raw.sender,
|
||||
state_key: raw.state_key,
|
||||
unsigned: raw.unsigned,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for CanonicalAliasEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for CanonicalAliasEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -208,39 +160,6 @@ impl<'de> Deserialize<'de> for EventResult<CanonicalAliasEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for CanonicalAliasEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::CanonicalAliasEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self { alias: raw.alias })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for CanonicalAliasEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
mod raw {
|
||||
use super::*;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! Types for the *m.room.encrypted* event.
|
||||
|
||||
use std::{convert::TryFrom, str::FromStr};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{DeviceId, EventId, RoomId, UserId};
|
||||
use serde::{de::Error, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
@ -92,58 +90,6 @@ impl<'de> Deserialize<'de> for EventResult<EncryptedEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for EncryptedEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::EncryptedEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let content = match raw.content {
|
||||
raw::EncryptedEventContent::OlmV1Curve25519AesSha2(content) => {
|
||||
EncryptedEventContent::OlmV1Curve25519AesSha2(content)
|
||||
}
|
||||
raw::EncryptedEventContent::MegolmV1AesSha2(content) => {
|
||||
EncryptedEventContent::MegolmV1AesSha2(content)
|
||||
}
|
||||
raw::EncryptedEventContent::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.");
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
content,
|
||||
event_id: raw.event_id,
|
||||
origin_server_ts: raw.origin_server_ts,
|
||||
room_id: raw.room_id,
|
||||
sender: raw.sender,
|
||||
unsigned: raw.unsigned,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for EncryptedEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for EncryptedEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -219,49 +165,6 @@ impl<'de> Deserialize<'de> for EventResult<EncryptedEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for EncryptedEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::EncryptedEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
match raw {
|
||||
raw::EncryptedEventContent::OlmV1Curve25519AesSha2(content) => {
|
||||
Ok(EncryptedEventContent::OlmV1Curve25519AesSha2(content))
|
||||
}
|
||||
raw::EncryptedEventContent::MegolmV1AesSha2(content) => {
|
||||
Ok(EncryptedEventContent::MegolmV1AesSha2(content))
|
||||
}
|
||||
raw::EncryptedEventContent::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for EncryptedEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for EncryptedEventContent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! Types for the *m.room.message* event.
|
||||
|
||||
use std::{convert::TryFrom, str::FromStr};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{
|
||||
@ -123,63 +121,6 @@ impl<'de> Deserialize<'de> for EventResult<MessageEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for MessageEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::MessageEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
content: match raw.content {
|
||||
raw::MessageEventContent::Audio(content) => MessageEventContent::Audio(content),
|
||||
raw::MessageEventContent::Emote(content) => MessageEventContent::Emote(content),
|
||||
raw::MessageEventContent::File(content) => MessageEventContent::File(content),
|
||||
raw::MessageEventContent::Image(content) => MessageEventContent::Image(content),
|
||||
raw::MessageEventContent::Location(content) => {
|
||||
MessageEventContent::Location(content)
|
||||
}
|
||||
raw::MessageEventContent::Notice(content) => MessageEventContent::Notice(content),
|
||||
raw::MessageEventContent::ServerNotice(content) => {
|
||||
MessageEventContent::ServerNotice(content)
|
||||
}
|
||||
raw::MessageEventContent::Text(content) => MessageEventContent::Text(content),
|
||||
raw::MessageEventContent::Video(content) => MessageEventContent::Video(content),
|
||||
raw::MessageEventContent::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.")
|
||||
}
|
||||
},
|
||||
event_id: raw.event_id,
|
||||
origin_server_ts: raw.origin_server_ts,
|
||||
room_id: raw.room_id,
|
||||
sender: raw.sender,
|
||||
unsigned: raw.unsigned,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for MessageEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for MessageEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -280,56 +221,6 @@ impl<'de> Deserialize<'de> for EventResult<MessageEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for MessageEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::MessageEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
match raw {
|
||||
raw::MessageEventContent::Audio(content) => Ok(MessageEventContent::Audio(content)),
|
||||
raw::MessageEventContent::Emote(content) => Ok(MessageEventContent::Emote(content)),
|
||||
raw::MessageEventContent::File(content) => Ok(MessageEventContent::File(content)),
|
||||
raw::MessageEventContent::Image(content) => Ok(MessageEventContent::Image(content)),
|
||||
raw::MessageEventContent::Location(content) => {
|
||||
Ok(MessageEventContent::Location(content))
|
||||
}
|
||||
raw::MessageEventContent::Notice(content) => Ok(MessageEventContent::Notice(content)),
|
||||
raw::MessageEventContent::ServerNotice(content) => {
|
||||
Ok(MessageEventContent::ServerNotice(content))
|
||||
}
|
||||
raw::MessageEventContent::Text(content) => Ok(MessageEventContent::Text(content)),
|
||||
raw::MessageEventContent::Video(content) => Ok(MessageEventContent::Video(content)),
|
||||
raw::MessageEventContent::__Nonexhaustive => {
|
||||
panic!("__Nonexhaustive enum variant is not intended for use.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for MessageEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
mod raw {
|
||||
use super::*;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! Types for the *m.room.name* event.
|
||||
|
||||
use std::{convert::TryFrom, str::FromStr};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
@ -84,52 +82,6 @@ impl<'de> Deserialize<'de> for EventResult<NameEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for NameEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::NameEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
content: NameEventContent {
|
||||
name: raw.content.name,
|
||||
},
|
||||
event_id: raw.event_id,
|
||||
origin_server_ts: raw.origin_server_ts,
|
||||
prev_content: raw
|
||||
.prev_content
|
||||
.map(|prev| NameEventContent { name: prev.name }),
|
||||
room_id: raw.room_id,
|
||||
sender: raw.sender,
|
||||
state_key: raw.state_key,
|
||||
unsigned: raw.unsigned,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for NameEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for NameEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -222,39 +174,6 @@ impl<'de> Deserialize<'de> for EventResult<NameEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for NameEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::NameEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self { name: raw.name })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for NameEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
mod raw {
|
||||
use super::*;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.room.power_levels* event.
|
||||
|
||||
use std::{collections::HashMap, convert::TryFrom, str::FromStr};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use js_int::{Int, UInt};
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
@ -141,70 +141,6 @@ impl<'de> Deserialize<'de> for EventResult<PowerLevelsEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for PowerLevelsEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::PowerLevelsEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
content: PowerLevelsEventContent {
|
||||
ban: raw.content.ban,
|
||||
events: raw.content.events,
|
||||
events_default: raw.content.events_default,
|
||||
invite: raw.content.invite,
|
||||
kick: raw.content.kick,
|
||||
redact: raw.content.redact,
|
||||
state_default: raw.content.state_default,
|
||||
users: raw.content.users,
|
||||
users_default: raw.content.users_default,
|
||||
notifications: raw.content.notifications,
|
||||
},
|
||||
event_id: raw.event_id,
|
||||
origin_server_ts: raw.origin_server_ts,
|
||||
prev_content: raw.prev_content.map(|prev| PowerLevelsEventContent {
|
||||
ban: prev.ban,
|
||||
events: prev.events,
|
||||
events_default: prev.events_default,
|
||||
invite: prev.invite,
|
||||
kick: prev.kick,
|
||||
redact: prev.redact,
|
||||
state_default: prev.state_default,
|
||||
users: prev.users,
|
||||
users_default: prev.users_default,
|
||||
notifications: prev.notifications,
|
||||
}),
|
||||
room_id: raw.room_id,
|
||||
sender: raw.sender,
|
||||
state_key: raw.state_key,
|
||||
unsigned: raw.unsigned,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for PowerLevelsEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for PowerLevelsEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -290,50 +226,6 @@ impl<'de> Deserialize<'de> for EventResult<PowerLevelsEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for PowerLevelsEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::PowerLevelsEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
ban: raw.ban,
|
||||
events: raw.events,
|
||||
events_default: raw.events_default,
|
||||
invite: raw.invite,
|
||||
kick: raw.kick,
|
||||
redact: raw.redact,
|
||||
state_default: raw.state_default,
|
||||
users: raw.users,
|
||||
users_default: raw.users_default,
|
||||
notifications: raw.notifications,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for PowerLevelsEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
mod raw {
|
||||
use super::*;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! Types for the *m.room.server_acl* event.
|
||||
|
||||
use std::{convert::TryFrom, str::FromStr};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
@ -110,56 +108,6 @@ impl<'de> Deserialize<'de> for EventResult<ServerAclEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for ServerAclEvent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::ServerAclEvent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
content: ServerAclEventContent {
|
||||
allow_ip_literals: raw.content.allow_ip_literals,
|
||||
allow: raw.content.allow,
|
||||
deny: raw.content.deny,
|
||||
},
|
||||
event_id: raw.event_id,
|
||||
origin_server_ts: raw.origin_server_ts,
|
||||
prev_content: raw.prev_content.map(|prev| ServerAclEventContent {
|
||||
allow_ip_literals: prev.allow_ip_literals,
|
||||
allow: prev.allow,
|
||||
deny: prev.deny,
|
||||
}),
|
||||
room_id: raw.room_id,
|
||||
unsigned: raw.unsigned,
|
||||
sender: raw.sender,
|
||||
state_key: raw.state_key,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for ServerAclEvent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for ServerAclEvent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -207,43 +155,6 @@ impl<'de> Deserialize<'de> for EventResult<ServerAclEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for ServerAclEventContent {
|
||||
type Err = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
let raw = match serde_json::from_str::<raw::ServerAclEventContent>(json) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
Ok(value) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
json: value,
|
||||
message: error.to_string(),
|
||||
}));
|
||||
}
|
||||
Err(error) => {
|
||||
return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
allow_ip_literals: raw.allow_ip_literals,
|
||||
allow: raw.allow,
|
||||
deny: raw.deny,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for ServerAclEventContent {
|
||||
type Error = InvalidEvent;
|
||||
|
||||
/// Attempt to create `Self` from parsing a string of JSON data.
|
||||
fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
FromStr::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
mod raw {
|
||||
use super::*;
|
||||
|
||||
|
179
src/stripped.rs
179
src/stripped.rs
@ -305,80 +305,6 @@ impl<'de> Deserialize<'de> for EventResult<StrippedState> {
|
||||
}
|
||||
}
|
||||
|
||||
// impl FromStr for StrippedState {
|
||||
// type Err = InvalidEvent;
|
||||
|
||||
// /// Attempt to create `Self` from parsing a string of JSON data.
|
||||
// fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
// let value = match serde_json::from_str::<Value>(json) {
|
||||
// Ok(value) => value,
|
||||
// Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
// Ok(value) => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: error.to_string(),
|
||||
// }));
|
||||
// }
|
||||
// Err(error) => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
// }
|
||||
// },
|
||||
// };
|
||||
|
||||
// let event_type_value = match value.get("type") {
|
||||
// Some(value) => value.clone(),
|
||||
// None => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: "missing field `type`".to_string(),
|
||||
// }))
|
||||
// }
|
||||
// };
|
||||
|
||||
// let event_type = match from_value::<EventType>(event_type_value.clone()) {
|
||||
// Ok(event_type) => event_type,
|
||||
// Err(error) => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: error.to_string(),
|
||||
// }))
|
||||
// }
|
||||
// };
|
||||
|
||||
// match event_type {
|
||||
// EventType::RoomAliases => Ok(StrippedState::RoomAliases(json.parse()?)),
|
||||
// EventType::RoomAvatar => Ok(StrippedState::RoomAvatar(json.parse()?)),
|
||||
// EventType::RoomCanonicalAlias => Ok(StrippedState::RoomCanonicalAlias(json.parse()?)),
|
||||
// EventType::RoomCreate => Ok(StrippedState::RoomCreate(json.parse()?)),
|
||||
// EventType::RoomGuestAccess => Ok(StrippedState::RoomGuestAccess(json.parse()?)),
|
||||
// EventType::RoomHistoryVisibility => {
|
||||
// Ok(StrippedState::RoomHistoryVisibility(json.parse()?))
|
||||
// }
|
||||
// EventType::RoomJoinRules => Ok(StrippedState::RoomJoinRules(json.parse()?)),
|
||||
// EventType::RoomMember => Ok(StrippedState::RoomMember(json.parse()?)),
|
||||
// EventType::RoomName => Ok(StrippedState::RoomName(json.parse()?)),
|
||||
// EventType::RoomPowerLevels => Ok(StrippedState::RoomPowerLevels(json.parse()?)),
|
||||
// EventType::RoomThirdPartyInvite => {
|
||||
// Ok(StrippedState::RoomThirdPartyInvite(json.parse()?))
|
||||
// }
|
||||
// EventType::RoomTopic => Ok(StrippedState::RoomTopic(json.parse()?)),
|
||||
// _ => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: "not a state event".to_string(),
|
||||
// })),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl<'a> TryFrom<&'a str> for StrippedState {
|
||||
// type Error = InvalidEvent;
|
||||
|
||||
// /// Attempt to create `Self` from parsing a string of JSON data.
|
||||
// fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
// FromStr::from_str(json)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Serialize for StrippedState {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -461,111 +387,6 @@ impl Serialize for StrippedState {
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl<C> FromStr for StrippedStateContent<C>
|
||||
// where
|
||||
// C: FromStr,
|
||||
// <C as FromStr>::Err: ToString,
|
||||
// {
|
||||
// type Err = InvalidEvent;
|
||||
|
||||
// /// Attempt to create `Self` from parsing a string of JSON data.
|
||||
// fn from_str(json: &str) -> Result<Self, Self::Err> {
|
||||
// let value = match serde_json::from_str::<Value>(json) {
|
||||
// Ok(value) => value,
|
||||
// Err(error) => match serde_json::from_str::<serde_json::Value>(json) {
|
||||
// Ok(value) => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: error.to_string(),
|
||||
// }));
|
||||
// }
|
||||
// Err(error) => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Deserialization { error }));
|
||||
// }
|
||||
// },
|
||||
// };
|
||||
|
||||
// let event_type_value = match value.get("type") {
|
||||
// Some(value) => value.clone(),
|
||||
// None => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: "missing field `type`".to_string(),
|
||||
// }))
|
||||
// }
|
||||
// };
|
||||
|
||||
// let event_type = match from_value::<EventType>(event_type_value.clone()) {
|
||||
// Ok(event_type) => event_type,
|
||||
// Err(error) => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: error.to_string(),
|
||||
// }))
|
||||
// }
|
||||
// };
|
||||
|
||||
// let content = match value.get("content") {
|
||||
// Some(content_value) => match content_value.as_object() {
|
||||
// Some(content) => content,
|
||||
// None => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: "field `content` must be an object".to_string(),
|
||||
// }))
|
||||
// }
|
||||
// },
|
||||
// None => {
|
||||
// return Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: "missing field `content`".to_string(),
|
||||
// }))
|
||||
// }
|
||||
// };
|
||||
|
||||
// // Unwrap is safe because we already know this can deserialize to a `Value`.
|
||||
// let json_string = to_string(content).unwrap();
|
||||
|
||||
// match event_type {
|
||||
// EventType::RoomAliases => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomAvatar => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomCanonicalAlias => {
|
||||
// stripped_state_content(&json_string, event_type, value)
|
||||
// }
|
||||
// EventType::RoomCreate => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomGuestAccess => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomHistoryVisibility => {
|
||||
// stripped_state_content(&json_string, event_type, value)
|
||||
// }
|
||||
// EventType::RoomJoinRules => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomMember => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomName => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomPowerLevels => stripped_state_content(&json_string, event_type, value),
|
||||
// EventType::RoomThirdPartyInvite => {
|
||||
// stripped_state_content(&json_string, event_type, value)
|
||||
// }
|
||||
// EventType::RoomTopic => stripped_state_content(&json_string, event_type, value),
|
||||
// _ => Err(InvalidEvent(InnerInvalidEvent::Validation {
|
||||
// json: value,
|
||||
// message: "not a state event".to_string(),
|
||||
// })),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl<'a, C> TryFrom<&'a str> for StrippedStateContent<C>
|
||||
// where
|
||||
// C: FromStr,
|
||||
// <C as FromStr>::Err: ToString,
|
||||
// {
|
||||
// type Error = InvalidEvent;
|
||||
|
||||
// /// Attempt to create `Self` from parsing a string of JSON data.
|
||||
// fn try_from(json: &'a str) -> Result<Self, Self::Error> {
|
||||
// FromStr::from_str(json)
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// Reduces the boilerplate in the match arms of `impl Deserialize for StrippedState`.
|
||||
// #[inline]
|
||||
// fn create_stripped_state(
|
||||
|
Loading…
x
Reference in New Issue
Block a user