pub fn new(msgtype: &str, data: JsonObject) -> serde_json::Result<Self> {
        fn from_json_object<T: DeserializeOwned>(obj: JsonObject) -> serde_json::Result<T> {
            serde_json::from_value(JsonValue::Object(obj))
        }

        Ok(match msgtype {
            "m.audio" => Self::Audio(from_json_object(data)?),
            "m.emote" => Self::Emote(from_json_object(data)?),
            "m.file" => Self::File(from_json_object(data)?),
            "m.image" => Self::Image(from_json_object(data)?),
            "m.location" => Self::Location(from_json_object(data)?),
            "m.notice" => Self::Notice(from_json_object(data)?),
            "m.server_notice" => Self::ServerNotice(from_json_object(data)?),
            "m.text" => Self::Text(from_json_object(data)?),
            "m.video" => Self::Video(from_json_object(data)?),
            #[cfg(feature = "unstable-pre-spec")]
            "m.key.verification.request" => Self::VerificationRequest(from_json_object(data)?),
            _ => Self::_Custom(CustomEventContent { msgtype: msgtype.to_owned(), data }),
        })
    }
/// Creates a new `MessageType` with the given `msgtype` string and data.
///
/// Prefer to use the public variants of `MessageType` where possible; this constructor is meant
/// be used for unsupported message types only and does not allow setting arbitrary data for
/// supported ones.
Creates a new `MessageType` with the given `msgtype` string and data.
Prefer to use the public variants of `MessageType` where possible; this constructor is meant
be used for unsupported message types only and does not allow setting arbitrary data for
supported ones.
Creates a new ` MessageType ` with the given ` msgtype ` string and data . Prefer to use the public variants of ` MessageType ` where possible ; this constructor is meant be used for unsupported message types only and does not allow setting arbitrary data for supported ones .
pub fn new(msgtype: &str, data: JsonObject) -> serde_json::Result<Self> {
        fn from_json_object<T: DeserializeOwned>(obj: JsonObject) -> serde_json::Result<T> {
            serde_json::from_value(JsonValue::Object(obj))
        }
        Ok(match msgtype {
            "m.audio" => Self::Audio(from_json_object(data)?),
            "m.emote" => Self::Emote(from_json_object(data)?),
            "m.file" => Self::File(from_json_object(data)?),
            "m.image" => Self::Image(from_json_object(data)?),
            "m.location" => Self::Location(from_json_object(data)?),
            "m.notice" => Self::Notice(from_json_object(data)?),
            "m.server_notice" => Self::ServerNotice(from_json_object(data)?),
            "m.text" => Self::Text(from_json_object(data)?),
            "m.video" => Self::Video(from_json_object(data)?),
            #[cfg(feature = "unstable-pre-spec")]
            "m.key.verification.request" => Self::VerificationRequest(from_json_object(data)?),
            _ => Self::_Custom(CustomEventContent { msgtype: msgtype.to_owned(), data }),
        })
    }
pub fn new ( msgtype : & str , data : JsonObject ) -> serde_json :: Result < Self > { fn from_json_object < T : DeserializeOwned > ( obj : JsonObject ) -> serde_json :: Result < T > { serde_json :: from_value ( JsonValue :: Object ( obj ) ) } Ok ( match msgtype { " " => Self :: Audio ( from_json_object ( data ) ? ) , " " => Self :: Emote ( from_json_object ( data ) ? ) , " " => Self :: File ( from_json_object ( data ) ? ) , " " => Self :: Image ( from_json_object ( data ) ? ) , " " => Self :: Location ( from_json_object ( data ) ? ) , " " => Self :: Notice ( from_json_object ( data ) ? ) , " " => Self :: ServerNotice ( from_json_object ( data ) ? ) , " " => Self :: Text ( from_json_object ( data ) ? ) , " " => Self :: Video ( from_json_object ( data ) ? ) , # [ cfg ( feature " " ) ] " " => Self :: VerificationRequest ( from_json_object ( data ) ? ) , _ => Self :: _Custom ( CustomEventContent { msgtype : msgtype . to_owned ( ) , data } ) , } ) }
Creates a new `MessageType` with the given `msgtype` string and data.
Creates a new ` MessageType ` with the given ` msgtype ` string and data .
msgtype
&str
data
JsonObject