Revise trait implementations

This commit is contained in:
Jonas Platte 2020-05-02 14:12:49 +02:00
parent a512df0321
commit ca5c65ef10
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
24 changed files with 115 additions and 140 deletions

View File

@ -95,7 +95,7 @@ impl ToTokens for RumaEvent {
Content::Struct(fields) => {
quote! {
#[doc = #content_docstring]
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
#[derive(Clone, Debug, serde::Serialize)]
pub struct #content_name {
#(#fields),*
}
@ -116,7 +116,7 @@ impl ToTokens for RumaEvent {
Content::Struct(fields) => {
quote! {
#[doc = #content_docstring]
#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
#[derive(Clone, Debug, serde::Deserialize)]
pub struct #content_name {
#(#fields),*
}
@ -216,7 +216,7 @@ impl ToTokens for RumaEvent {
let event_type_name = self.event_type.value();
let output = quote!(
#(#attrs)*
#[derive(Clone, PartialEq, Debug, serde::Serialize, ruma_events_macros::FromRaw)]
#[derive(Clone, Debug, serde::Serialize, ruma_events_macros::FromRaw)]
#[serde(rename = #event_type_name, tag = "type")]
pub struct #name {
#(#event_fields),*
@ -250,7 +250,7 @@ impl ToTokens for RumaEvent {
use super::*;
#(#attrs)*
#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
#[derive(Clone, Debug, serde::Deserialize)]
pub struct #name {
#(#event_fields),*
}

View File

@ -1,14 +1,10 @@
use std::{
borrow::Cow,
fmt::{Display, Formatter, Result as FmtResult},
};
use std::fmt::{Display, Formatter, Result as FmtResult};
use serde::{Deserialize, Serialize};
/// An encryption algorithm to be used to encrypt messages sent to a room.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
// Cow<str> because deserialization sometimes needs to copy to unescape things
#[serde(from = "Cow<'_, str>", into = "String")]
#[serde(from = "String", into = "String")]
pub enum Algorithm {
/// Olm version 1 using Curve25519, AES-256, and SHA-256.
OlmV1Curve25519AesSha2,
@ -40,22 +36,19 @@ impl Display for Algorithm {
}
}
impl From<Cow<'_, str>> for Algorithm {
fn from(s: Cow<'_, str>) -> Algorithm {
match &s as &str {
impl<T> From<T> for Algorithm
where
T: Into<String> + AsRef<str>,
{
fn from(s: T) -> Algorithm {
match s.as_ref() {
"m.olm.v1.curve25519-aes-sha2" => Algorithm::OlmV1Curve25519AesSha2,
"m.megolm.v1.aes-sha2" => Algorithm::MegolmV1AesSha2,
_ => Algorithm::Custom(s.into_owned()),
_ => Algorithm::Custom(s.into()),
}
}
}
impl From<&str> for Algorithm {
fn from(s: &str) -> Algorithm {
Algorithm::from(Cow::Borrowed(s))
}
}
impl From<Algorithm> for String {
fn from(algorithm: Algorithm) -> String {
algorithm.to_string()

View File

@ -25,7 +25,7 @@ ruma_event! {
}
/// An ICE (Interactive Connectivity Establishment) candidate.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Candidate {
/// The SDP "a" line of the candidate.

View File

@ -10,7 +10,7 @@ use serde::Serialize;
use serde_json::Value as JsonValue;
/// A custom event not covered by the Matrix specification.
#[derive(Clone, Debug, FromRaw, PartialEq, Serialize)]
#[derive(Clone, Debug, FromRaw, Serialize)]
pub struct CustomEvent {
/// The event's content.
pub content: CustomEventContent,
@ -38,7 +38,7 @@ impl Event for CustomEvent {
}
/// A custom room event not covered by the Matrix specification.
#[derive(Clone, Debug, FromRaw, PartialEq, Serialize)]
#[derive(Clone, Debug, FromRaw, Serialize)]
pub struct CustomRoomEvent {
/// The event's content.
pub content: CustomRoomEventContent,
@ -108,7 +108,7 @@ impl RoomEvent for CustomRoomEvent {
}
/// A custom state event not covered by the Matrix specification.
#[derive(Clone, Debug, FromRaw, PartialEq, Serialize)]
#[derive(Clone, Debug, FromRaw, Serialize)]
pub struct CustomStateEvent {
/// The event's content.
pub content: CustomStateEventContent,
@ -204,7 +204,7 @@ pub(crate) mod raw {
};
/// A custom event not covered by the Matrix specification.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct CustomEvent {
/// The event's content.
pub content: CustomEventContent,
@ -214,7 +214,7 @@ pub(crate) mod raw {
}
/// A custom room event not covered by the Matrix specification.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct CustomRoomEvent {
/// The event's content.
pub content: CustomRoomEventContent,
@ -236,7 +236,7 @@ pub(crate) mod raw {
}
/// A custom state event not covered by the Matrix specification.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct CustomStateEvent {
/// The event's content.
pub content: CustomStateEventContent,

View File

@ -1,14 +1,10 @@
use std::{
borrow::Cow,
fmt::{Display, Formatter, Result as FmtResult},
};
use std::fmt::{Display, Formatter, Result as FmtResult};
use serde::{Deserialize, Serialize};
/// The type of an event.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
// Cow<str> because deserialization sometimes needs to copy to unescape things
#[serde(from = "Cow<'_, str>", into = "String")]
#[serde(from = "String", into = "String")]
pub enum EventType {
/// m.call.answer
CallAnswer,
@ -204,9 +200,12 @@ impl Display for EventType {
}
}
impl From<Cow<'_, str>> for EventType {
fn from(s: Cow<'_, str>) -> EventType {
match &s as &str {
impl<T> From<T> for EventType
where
T: Into<String> + AsRef<str>,
{
fn from(s: T) -> EventType {
match s.as_ref() {
"m.call.answer" => EventType::CallAnswer,
"m.call.candidates" => EventType::CallCandidates,
"m.call.hangup" => EventType::CallHangup,
@ -250,17 +249,11 @@ impl From<Cow<'_, str>> for EventType {
"m.sticker" => EventType::Sticker,
"m.tag" => EventType::Tag,
"m.typing" => EventType::Typing,
_ => EventType::Custom(s.into_owned()),
_ => EventType::Custom(s.into()),
}
}
}
impl<'a> From<&str> for EventType {
fn from(s: &str) -> EventType {
EventType::from(Cow::Borrowed(s))
}
}
impl From<EventType> for String {
fn from(event_type: EventType) -> String {
event_type.to_string()

View File

@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use crate::{EventType, FromRaw};
/// A list of users to ignore.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(rename = "m.ignored_user_list", tag = "type")]
pub struct IgnoredUserListEvent {
/// The event's content.
@ -24,7 +24,7 @@ impl FromRaw for IgnoredUserListEvent {
}
/// The payload for `IgnoredUserListEvent`.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
pub struct IgnoredUserListEventContent {
/// A list of users to ignore.
#[serde(with = "ruma_serde::vec_as_map_of_empty")]
@ -110,8 +110,8 @@ mod tests {
assert_matches!(
from_json_value::<EventJson<IgnoredUserListEvent>>(json)
.unwrap()
.deserialize()
.unwrap()
.deserialize()
.unwrap(),
IgnoredUserListEvent {
content: IgnoredUserListEventContent { ignored_users, },

View File

@ -95,12 +95,6 @@ impl<T> Debug for EventJson<T> {
}
}
impl<T> PartialEq for EventJson<T> {
fn eq(&self, other: &Self) -> bool {
self.json.get() == other.json.get()
}
}
impl<'de, T> Deserialize<'de> for EventJson<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where

View File

@ -1,9 +1,6 @@
//! Types for the *m.key.verification.cancel* event.
use std::{
borrow::Cow,
fmt::{Display, Formatter, Result as FmtResult},
};
use std::fmt::{Display, Formatter, Result as FmtResult};
use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize};
@ -34,8 +31,7 @@ ruma_event! {
///
/// Custom error codes should use the Java package naming convention.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
// Cow<str> because deserialization sometimes needs to copy to unescape things
#[serde(from = "Cow<'_, str>", into = "String")]
#[serde(from = "String", into = "String")]
pub enum CancelCode {
/// The user cancelled the verification.
User,
@ -103,9 +99,12 @@ impl Display for CancelCode {
}
}
impl From<Cow<'_, str>> for CancelCode {
fn from(s: Cow<'_, str>) -> CancelCode {
match &s as &str {
impl<T> From<T> for CancelCode
where
T: Into<String> + AsRef<str>,
{
fn from(s: T) -> CancelCode {
match s.as_ref() {
"m.user" => CancelCode::User,
"m.timeout" => CancelCode::Timeout,
"m.unknown_transaction" => CancelCode::UnknownTransaction,
@ -115,17 +114,11 @@ impl From<Cow<'_, str>> for CancelCode {
"m.user_mismatch" => CancelCode::UserMismatch,
"m.invalid_message" => CancelCode::InvalidMessage,
"m.accepted" => CancelCode::Accepted,
_ => CancelCode::Custom(s.into_owned()),
_ => CancelCode::Custom(s.into()),
}
}
}
impl From<&str> for CancelCode {
fn from(s: &str) -> CancelCode {
CancelCode::from(Cow::Borrowed(s))
}
}
impl From<CancelCode> for String {
fn from(cancel_code: CancelCode) -> String {
cancel_code.to_string()

View File

@ -12,7 +12,7 @@ use crate::{EventType, InvalidInput, TryFromRaw};
/// Begins an SAS key verification process.
///
/// Typically sent as a to-device event.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(tag = "type", rename = "m.key.verification.start")]
pub struct StartEvent {
/// The event's content.
@ -20,7 +20,7 @@ pub struct StartEvent {
}
/// The payload of an *m.key.verification.start* event.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(untagged)]
pub enum StartEventContent {
/// The *m.sas.v1* verification method.
@ -103,14 +103,14 @@ pub(crate) mod raw {
/// Begins an SAS key verification process.
///
/// Typically sent as a to-device event.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct StartEvent {
/// The event's content.
pub content: StartEventContent,
}
/// The payload of an *m.key.verification.start* event.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum StartEventContent {
/// The *m.sas.v1* verification method.
MSasV1(MSasV1Content),
@ -158,7 +158,7 @@ pub(crate) mod raw {
}
/// The payload of an *m.key.verification.start* event using the *m.sas.v1* method.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "method", rename = "m.sas.v1")]
pub struct MSasV1Content {
/// The device ID which is initiating the process.
@ -193,7 +193,7 @@ pub struct MSasV1Content {
}
/// Options for creating an `MSasV1Content` with `MSasV1Content::new`.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct MSasV1ContentOptions {
/// The device ID which is initiating the process.
pub from_device: DeviceId,

View File

@ -224,7 +224,7 @@ pub trait StateEvent: RoomEvent {
/// Extra information about an event that is not incorporated into the event's
/// hash.
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct UnsignedData {
/// The time in milliseconds that has elapsed since the event was sent. This
/// field is generated by the local homeserver, and may be incorrect if the
@ -232,9 +232,11 @@ pub struct UnsignedData {
/// cause the age to either be negative or greater than it actually is.
#[serde(skip_serializing_if = "Option::is_none")]
pub age: Option<Int>,
/// The event that redacted this event, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub redacted_because: Option<EventJson<RedactionEvent>>,
/// The client-supplied transaction ID, if the client being given the event
/// is the same one which sent it.
#[serde(skip_serializing_if = "Option::is_none")]

View File

@ -31,7 +31,7 @@ ruma_event! {
///
/// For example, some rules may only be applied for messages from a particular sender, a particular
/// room, or by default. The push ruleset contains the entire set of scopes and rules.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Ruleset {
/// These rules configure behaviour for (unencrypted) messages that match certain patterns.
pub content: Vec<PatternedPushRule>,
@ -56,7 +56,7 @@ pub struct Ruleset {
///
/// These rules are stored on the user's homeserver. They are manually configured by the user, who
/// can create and view them via the Client/Server API.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PushRule {
/// Actions to determine if and how a notification is delivered for events matching this rule.
pub actions: Vec<Action>,
@ -74,7 +74,7 @@ pub struct PushRule {
/// Like `PushRule`, but with an additional `conditions` field.
///
/// Only applicable to underride and override rules.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ConditionalPushRule {
/// Actions to determine if and how a notification is delivered for events matching this rule.
pub actions: Vec<Action>,
@ -97,7 +97,7 @@ pub struct ConditionalPushRule {
/// Like `PushRule`, but with an additional `pattern` field.
///
/// Only applicable to content rules.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PatternedPushRule {
/// Actions to determine if and how a notification is delivered for events matching this rule.
pub actions: Vec<Action>,
@ -116,7 +116,7 @@ pub struct PatternedPushRule {
}
/// An action affects if and how a notification is delivered for a matching event.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum Action {
/// This causes each matching event to generate a notification.
Notify,
@ -229,7 +229,7 @@ impl<'de> Deserialize<'de> for Action {
}
/// Values for the `set_tweak` action.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "set_tweak", rename_all = "lowercase")]
pub enum Tweak {
/// A string representing the sound to be played when this notification arrives.
@ -256,7 +256,7 @@ pub enum Tweak {
}
/// A condition that must apply for an associated push rule's action to be taken.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum PushCondition {
/// This is a glob pattern match on a field of the event.
EventMatch(EventMatchCondition),
@ -355,7 +355,7 @@ impl<'de> Deserialize<'de> for PushCondition {
}
/// A push condition that matches a glob pattern match on a field of the event.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "kind", rename = "event_match")]
pub struct EventMatchCondition {
/// The dot-separated field of the event to match.
@ -369,7 +369,7 @@ pub struct EventMatchCondition {
}
/// A push condition that matches the current number of members in the room.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "kind", rename = "room_member_count")]
pub struct RoomMemberCountCondition {
/// A decimal integer optionally prefixed by one of `==`, `<`, `>`, `>=` or `<=`.
@ -381,7 +381,7 @@ pub struct RoomMemberCountCondition {
/// A push condition that takes into account the current power levels in the room, ensuring the
/// sender of the event has high enough power to trigger the notification.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "kind", rename = "sender_notification_permission")]
pub struct SenderNotificationPermissionCondition {
/// The field in the power level event the user needs a minimum power level for.

View File

@ -29,7 +29,7 @@ ruma_event! {
}
/// A collection of receipts.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Receipts {
/// A collection of users who have sent *m.read* receipts for this event.
#[serde(default, rename = "m.read")]
@ -42,7 +42,7 @@ pub struct Receipts {
pub type UserReceipts = BTreeMap<UserId, Receipt>;
/// An acknowledgement of an event.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Receipt {
/// The time when the receipt was sent.
#[serde(

View File

@ -28,7 +28,7 @@ pub mod tombstone;
pub mod topic;
/// Metadata about an image.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ImageInfo {
/// The height of the image in pixels.
#[serde(rename = "h", skip_serializing_if = "Option::is_none")]
@ -60,7 +60,7 @@ pub struct ImageInfo {
}
/// Metadata about a thumbnail.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ThumbnailInfo {
/// The height of the thumbnail in pixels.
#[serde(rename = "h", skip_serializing_if = "Option::is_none")]
@ -80,7 +80,7 @@ pub struct ThumbnailInfo {
}
/// A file sent to a room with end-to-end encryption enabled.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EncryptedFile {
/// The URL to the file.
pub url: String,
@ -100,7 +100,7 @@ pub struct EncryptedFile {
}
/// A [JSON Web Key](https://tools.ietf.org/html/rfc7517#appendix-A.3) object.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct JsonWebKey {
/// Key type. Must be `oct`.
pub kty: String,

View File

@ -32,7 +32,7 @@ ruma_event! {
}
/// A reference to an old room replaced during a room version upgrade.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PreviousRoom {
/// The ID of the old room.
pub room_id: RoomId,

View File

@ -12,7 +12,7 @@ use crate::{Algorithm, EventType, FromRaw, UnsignedData};
///
/// This type is to be used within a room. For a to-device event, use `EncryptedEventContent`
/// directly.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(tag = "type", rename = "m.room.encrypted")]
pub struct EncryptedEvent {
/// The event's content.
@ -33,12 +33,12 @@ pub struct EncryptedEvent {
pub sender: UserId,
/// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if = "ruma_serde::is_default")]
#[serde(skip_serializing_if = "UnsignedData::is_empty")]
pub unsigned: UnsignedData,
}
/// The payload for `EncryptedEvent`.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(untagged)]
pub enum EncryptedEventContent {
/// An event encrypted with *m.olm.v1.curve25519-aes-sha2*.
@ -106,7 +106,7 @@ pub(crate) mod raw {
///
/// This type is to be used within a room. For a to-device event, use `EncryptedEventContent`
/// directly.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct EncryptedEvent {
/// The event's content.
pub content: EncryptedEventContent,
@ -130,7 +130,7 @@ pub(crate) mod raw {
}
/// The payload for `EncryptedEvent`.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum EncryptedEventContent {
/// An event encrypted with *m.olm.v1.curve25519-aes-sha2*.
OlmV1Curve25519AesSha2(OlmV1Curve25519AesSha2Content),
@ -192,7 +192,7 @@ pub(crate) mod raw {
}
/// The payload for `EncryptedEvent` using the *m.olm.v1.curve25519-aes-sha2* algorithm.
#[derive(Clone, Debug, Serialize, PartialEq, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OlmV1Curve25519AesSha2Content {
/// The encryption algorithm used to encrypt this event.
pub algorithm: Algorithm,
@ -207,7 +207,7 @@ pub struct OlmV1Curve25519AesSha2Content {
/// Ciphertext information holding the ciphertext and message type.
///
/// Used for messages encrypted with the *m.olm.v1.curve25519-aes-sha2* algorithm.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CiphertextInfo {
/// The encrypted payload.
pub body: String,
@ -218,7 +218,7 @@ pub struct CiphertextInfo {
}
/// The payload for `EncryptedEvent` using the *m.megolm.v1.aes-sha2* algorithm.
#[derive(Clone, Debug, Serialize, PartialEq, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MegolmV1AesSha2Content {
/// The encryption algorithm used to encrypt this event.
pub algorithm: Algorithm,

View File

@ -99,7 +99,7 @@ impl_enum! {
}
/// Information about a third party invitation.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ThirdPartyInvite {
/// A name which can be displayed to represent the user instead of their third party
/// identifier.
@ -112,7 +112,7 @@ pub struct ThirdPartyInvite {
/// A block of content which has been signed, which servers can use to verify a third party
/// invitation.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SignedContent {
/// The invited Matrix user ID.
///
@ -128,7 +128,7 @@ pub struct SignedContent {
}
/// Translation of the membership change in `m.room.member` event.
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum MembershipChange {
/// No change.
None,

View File

@ -12,7 +12,7 @@ use crate::{EventType, FromRaw, UnsignedData};
pub mod feedback;
/// A message sent to a room.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(rename = "m.room.message", tag = "type")]
pub struct MessageEvent {
/// The event's content.
@ -39,7 +39,7 @@ pub struct MessageEvent {
/// The payload for `MessageEvent`.
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(untagged)]
pub enum MessageEventContent {
/// An audio message.
@ -135,7 +135,7 @@ pub(crate) mod raw {
use crate::UnsignedData;
/// A message sent to a room.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct MessageEvent {
/// The event's content.
pub content: MessageEventContent,
@ -160,7 +160,7 @@ pub(crate) mod raw {
/// The payload for `MessageEvent`.
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum MessageEventContent {
/// An audio message.
Audio(AudioMessageEventContent),
@ -295,7 +295,7 @@ pub enum MessageType {
}
/// The payload for an audio message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.audio")]
pub struct AudioMessageEventContent {
/// The textual representation of this message.
@ -316,7 +316,7 @@ pub struct AudioMessageEventContent {
}
/// Metadata about an audio clip.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AudioInfo {
/// The duration of the audio in milliseconds.
#[serde(skip_serializing_if = "Option::is_none")]
@ -332,7 +332,7 @@ pub struct AudioInfo {
}
/// The payload for an emote message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.emote")]
pub struct EmoteMessageEventContent {
/// The emote action to perform.
@ -349,7 +349,7 @@ pub struct EmoteMessageEventContent {
}
/// The payload for a file message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.file")]
pub struct FileMessageEventContent {
/// A human-readable description of the file. This is recommended to be the filename of the
@ -375,7 +375,7 @@ pub struct FileMessageEventContent {
}
/// Metadata about a file.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FileInfo {
/// The mimetype of the file, e.g. "application/msword."
#[serde(skip_serializing_if = "Option::is_none")]
@ -399,7 +399,7 @@ pub struct FileInfo {
}
/// The payload for an image message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.image")]
pub struct ImageMessageEventContent {
/// A textual representation of the image. This could be the alt text of the image, the filename
@ -421,7 +421,7 @@ pub struct ImageMessageEventContent {
}
/// The payload for a location message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.location")]
pub struct LocationMessageEventContent {
/// A description of the location e.g. "Big Ben, London, UK,"or some kind of content description
@ -437,7 +437,7 @@ pub struct LocationMessageEventContent {
}
/// Thumbnail info associated with a location.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LocationInfo {
/// Metadata about the image referred to in `thumbnail_url` or `thumbnail_file`.
#[serde(skip_serializing_if = "Option::is_none")]
@ -455,7 +455,7 @@ pub struct LocationInfo {
}
/// The payload for a notice message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.notice")]
pub struct NoticeMessageEventContent {
/// The notice text to send.
@ -477,7 +477,7 @@ pub struct NoticeMessageEventContent {
}
/// The payload for a server notice message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.server_notice")]
pub struct ServerNoticeMessageEventContent {
/// A human-readable description of the notice.
@ -500,7 +500,7 @@ pub struct ServerNoticeMessageEventContent {
}
/// Types of server notices.
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum ServerNoticeType {
/// The server has exceeded some limit which requires the server administrator to intervene.
#[serde(rename = "m.server_notice.usage_limit_reached")]
@ -514,7 +514,7 @@ pub enum ServerNoticeType {
}
/// Types of usage limits.
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum LimitType {
/// The server's number of active users in the last 30 days has exceeded the maximum.
///
@ -531,7 +531,7 @@ pub enum LimitType {
}
/// The payload for a text message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.text")]
pub struct TextMessageEventContent {
/// The body of the message.
@ -553,7 +553,7 @@ pub struct TextMessageEventContent {
}
/// The payload for a video message.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.video")]
pub struct VideoMessageEventContent {
/// A description of the video, e.g. "Gangnam Style," or some kind of content description for
@ -575,7 +575,7 @@ pub struct VideoMessageEventContent {
}
/// Metadata about a video.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct VideoInfo {
/// The duration of the video in milliseconds.
#[serde(skip_serializing_if = "Option::is_none")]
@ -615,7 +615,7 @@ pub struct VideoInfo {
/// Information about related messages for
/// [rich replies](https://matrix.org/docs/spec/client_server/r0.5.0#rich-replies).
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RelatesTo {
/// Information about another message being replied to.
#[serde(rename = "m.in_reply_to")]
@ -623,7 +623,7 @@ pub struct RelatesTo {
}
/// Information about the event a "rich reply" is replying to.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct InReplyTo {
/// The event being replied to.
pub event_id: EventId,

View File

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::{EventType, InvalidInput, TryFromRaw, UnsignedData};
/// A human-friendly room name designed to be displayed to the end-user.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(rename = "m.room.name", tag = "type")]
pub struct NameEvent {
/// The event's content.
@ -36,12 +36,12 @@ pub struct NameEvent {
pub state_key: String,
/// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if = "ruma_serde::is_default")]
#[serde(skip_serializing_if = "UnsignedData::is_empty")]
pub unsigned: UnsignedData,
}
/// The payload for `NameEvent`.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
pub struct NameEventContent {
/// The name of the room. This MUST NOT exceed 255 bytes.
pub(crate) name: Option<String>,
@ -109,7 +109,7 @@ pub(crate) mod raw {
use super::*;
/// A human-friendly room name designed to be displayed to the end-user.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct NameEvent {
/// The event's content.
pub content: NameEventContent,
@ -139,7 +139,7 @@ pub(crate) mod raw {
}
/// The payload of a `NameEvent`.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct NameEventContent {
/// The name of the room. This MUST NOT exceed 255 bytes.
// The spec says "A room with an m.room.name event with an absent, null, or empty name field

View File

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::{EventType, FromRaw, UnsignedData};
/// An event to indicate which servers are permitted to participate in the room.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[serde(rename = "m.room.server_acl", tag = "type")]
pub struct ServerAclEvent {
/// The event's content.
@ -41,7 +41,7 @@ pub struct ServerAclEvent {
}
/// The payload for `ServerAclEvent`.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
pub struct ServerAclEventContent {
/// True to allow server names that are IP address literals. False to deny. Defaults to true if
/// missing or otherwise not a boolean.
@ -108,7 +108,7 @@ pub(crate) mod raw {
use super::*;
/// An event to indicate which servers are permitted to participate in the room.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct ServerAclEvent {
/// The event's content.
pub content: ServerAclEventContent,
@ -138,7 +138,7 @@ pub(crate) mod raw {
}
/// The payload for `ServerAclEvent`.
#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct ServerAclEventContent {
/// True to allow server names that are IP address literals. False to deny. Defaults to true
/// if missing or otherwise not a boolean.

View File

@ -30,7 +30,7 @@ ruma_event! {
}
/// A public key for signing a third party invite token.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PublicKey {
/// An optional URL which can be fetched to validate whether the key has been revoked.
///

View File

@ -60,7 +60,7 @@ impl_enum! {
}
/// Information about a requested key.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RequestedKeyInfo {
/// The encryption algorithm the requested key in this event is to be used with.
pub algorithm: Algorithm,

View File

@ -65,7 +65,7 @@ pub enum AnyStrippedStateEvent {
}
/// A "stripped-down" version of a core state event.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
pub struct StrippedStateEvent<C> {
/// Data specific to the event type.
pub content: C,

View File

@ -18,7 +18,7 @@ ruma_event! {
}
/// Information about a tag.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct TagInfo {
/// Value to use for lexicographically ordering rooms with this tag.
#[serde(skip_serializing_if = "Option::is_none")]

View File

@ -24,7 +24,7 @@ use crate::{
/// To-device versions of events that will appear in the to-device part of a
/// sync response.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
#[allow(clippy::large_enum_variant)]
pub enum AnyToDeviceEvent {
/// To-device version of the "m.dummy" event.
@ -51,7 +51,7 @@ pub enum AnyToDeviceEvent {
KeyVerificationRequest(ToDeviceVerificationRequest),
}
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, Serialize)]
/// To-device event.
pub struct ToDeviceEvent<C> {
/// The unique identifier for the user who sent this event.