From 6f093f70ed9e08f82e5521b976d167ecf86f4a2f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 13 Jan 2019 21:58:34 +0100 Subject: [PATCH 1/2] Use nested imports, misc. import changes * Bring imports into a consistent order (std, crates, internal) * Replace super::super-imports by crate-relative ones --- .rustfmt.toml | 1 + src/collections/all.rs | 41 ++++++++++++++++++----------------------- src/collections/only.rs | 28 +++++++++++++--------------- src/direct.rs | 8 +++++--- src/lib.rs | 6 ++++-- src/presence.rs | 20 ++++++-------------- src/room/message.rs | 15 +++++++-------- src/stripped.rs | 26 ++++++++++---------------- 8 files changed, 64 insertions(+), 81 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..7d2cf549 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +merge_imports = true diff --git a/src/collections/all.rs b/src/collections/all.rs index 5654405d..e3f03c9d 100644 --- a/src/collections/all.rs +++ b/src/collections/all.rs @@ -1,34 +1,28 @@ //! Enums for heterogeneous collections of events, inclusive for every event type that implements //! the trait of the same name. -use call::answer::AnswerEvent; -use call::candidates::CandidatesEvent; -use call::hangup::HangupEvent; -use call::invite::InviteEvent; +use call::{ + answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, +}; use direct::DirectEvent; use presence::PresenceEvent; use receipt::ReceiptEvent; -use room::aliases::AliasesEvent; -use room::avatar::AvatarEvent; -use room::canonical_alias::CanonicalAliasEvent; -use room::create::CreateEvent; -use room::guest_access::GuestAccessEvent; -use room::history_visibility::HistoryVisibilityEvent; -use room::join_rules::JoinRulesEvent; -use room::member::MemberEvent; -use room::message::MessageEvent; -use room::name::NameEvent; -use room::pinned_events::PinnedEventsEvent; -use room::power_levels::PowerLevelsEvent; -use room::redaction::RedactionEvent; -use room::third_party_invite::ThirdPartyInviteEvent; -use room::topic::TopicEvent; +use room::{ + aliases::AliasesEvent, avatar::AvatarEvent, canonical_alias::CanonicalAliasEvent, + create::CreateEvent, guest_access::GuestAccessEvent, + history_visibility::HistoryVisibilityEvent, join_rules::JoinRulesEvent, member::MemberEvent, + message::MessageEvent, name::NameEvent, pinned_events::PinnedEventsEvent, + power_levels::PowerLevelsEvent, redaction::RedactionEvent, + third_party_invite::ThirdPartyInviteEvent, topic::TopicEvent, +}; use tag::TagEvent; use typing::TypingEvent; -use {CustomEvent, CustomRoomEvent, CustomStateEvent, EventType}; +use CustomEvent; +use CustomRoomEvent; +use CustomStateEvent; +use EventType; -use serde::de::Error; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; /// A basic event, room event, or state event. @@ -425,7 +419,8 @@ impl<'de> Deserialize<'de> for Event { }; Ok(Event::CustomState(event)) - } else if value.get("event_id").is_some() && value.get("room_id").is_some() + } else if value.get("event_id").is_some() + && value.get("room_id").is_some() && value.get("sender").is_some() { let event = match from_value::(value) { diff --git a/src/collections/only.rs b/src/collections/only.rs index 50e1d5e4..1ea1d9ca 100644 --- a/src/collections/only.rs +++ b/src/collections/only.rs @@ -1,24 +1,22 @@ //! Enums for heterogeneous collections of events, exclusive to event types that implement "at //! most" the trait of the same name. -use call::answer::AnswerEvent; -use call::candidates::CandidatesEvent; -use call::hangup::HangupEvent; -use call::invite::InviteEvent; -use direct::DirectEvent; -use presence::PresenceEvent; -use receipt::ReceiptEvent; -use room::message::MessageEvent; -use room::redaction::RedactionEvent; -use tag::TagEvent; -use typing::TypingEvent; -use {CustomEvent, CustomRoomEvent, EventType}; - -use serde::de::Error; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; pub use super::all::StateEvent; +use call::{ + answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, +}; +use direct::DirectEvent; +use presence::PresenceEvent; +use receipt::ReceiptEvent; +use room::{message::MessageEvent, redaction::RedactionEvent}; +use tag::TagEvent; +use typing::TypingEvent; +use CustomEvent; +use CustomRoomEvent; +use EventType; /// A basic event. #[derive(Clone, Debug)] diff --git a/src/direct.rs b/src/direct.rs index f3f4c278..8f3d1362 100644 --- a/src/direct.rs +++ b/src/direct.rs @@ -22,9 +22,11 @@ mod tests { use ruma_identifiers::{RoomId, UserId}; use serde_json::{from_str, to_string}; - use super::super::EventType; - use collections; - use direct::{DirectEvent, DirectEventContent}; + use crate::{ + collections, + direct::{DirectEvent, DirectEventContent}, + EventType, + }; #[test] fn serialization() { diff --git a/src/lib.rs b/src/lib.rs index bbb8382a..3be19fde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,8 +110,10 @@ extern crate serde_json; use std::fmt::{Debug, Display, Error as FmtError, Formatter, Result as FmtResult}; use ruma_identifiers::{EventId, RoomId, UserId}; -use serde::de::{Error as SerdeError, Visitor}; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{ + de::{Error as SerdeError, Visitor}, + Deserialize, Deserializer, Serialize, Serializer, +}; use serde_json::Value; #[macro_use] diff --git a/src/presence.rs b/src/presence.rs index 64a05187..44b3d64f 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -59,12 +59,13 @@ impl_enum! { #[cfg(test)] mod tests { - use serde_json::{from_str, to_string}; use std::convert::TryFrom; use ruma_identifiers::UserId; + use serde_json::{from_str, to_string}; + use super::{PresenceEvent, PresenceEventContent, PresenceState}; - use super::super::{EventType}; + use crate::EventType; /// Test serialization and deserialization of example m.presence event from the spec /// https://github.com/turt2live/matrix-doc/blob/master/event-schemas/examples/m.presence @@ -84,18 +85,9 @@ mod tests { let serialized_event = r#"{"content":{"avatar_url":"mxc://localhost:wefuiwegh8742w","currently_active":false,"last_active_ago":2478593,"presence":"online"},"type":"m.presence","sender":"@example:localhost"}"#; - assert_eq!( - to_string(&event).unwrap(), - serialized_event - ); + assert_eq!(to_string(&event).unwrap(), serialized_event); let deserialized_event = from_str::(serialized_event).unwrap(); - assert_eq!( - deserialized_event.content, - event.content - ); - assert_eq!( - deserialized_event.sender, - event.sender - ); + assert_eq!(deserialized_event.content, event.content); + assert_eq!(deserialized_event.sender, event.sender); } } diff --git a/src/room/message.rs b/src/room/message.rs index 4f884af3..e4763d8a 100644 --- a/src/room/message.rs +++ b/src/room/message.rs @@ -1,7 +1,6 @@ //! Types for the *m.room.message* event. -use serde::de::Error; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; use super::{ImageInfo, ThumbnailInfo}; @@ -396,17 +395,17 @@ mod tests { assert_eq!( from_str::( r#"{"body":"test","msgtype":"m.audio","url":"http://example.com/audio.mp3"}"# - ).unwrap(), + ) + .unwrap(), message_event_content ); } #[test] fn deserialization_failure() { - assert!( - from_str::( - r#"{"body":"test","msgtype":"m.location","url":"http://example.com/audio.mp3"}"# - ).is_err() - ); + assert!(from_str::( + r#"{"body":"test","msgtype":"m.location","url":"http://example.com/audio.mp3"}"# + ) + .is_err()); } } diff --git a/src/stripped.rs b/src/stripped.rs index 67755b25..b852e0f5 100644 --- a/src/stripped.rs +++ b/src/stripped.rs @@ -6,22 +6,17 @@ //! the other fields are otherwise inapplicable. use ruma_identifiers::UserId; -use serde::de::Error; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; -use room::aliases::AliasesEventContent; -use room::avatar::AvatarEventContent; -use room::canonical_alias::CanonicalAliasEventContent; -use room::create::CreateEventContent; -use room::guest_access::GuestAccessEventContent; -use room::history_visibility::HistoryVisibilityEventContent; -use room::join_rules::JoinRulesEventContent; -use room::member::MemberEventContent; -use room::name::NameEventContent; -use room::power_levels::PowerLevelsEventContent; -use room::third_party_invite::ThirdPartyInviteEventContent; -use room::topic::TopicEventContent; +use room::{ + aliases::AliasesEventContent, avatar::AvatarEventContent, + canonical_alias::CanonicalAliasEventContent, create::CreateEventContent, + guest_access::GuestAccessEventContent, history_visibility::HistoryVisibilityEventContent, + join_rules::JoinRulesEventContent, member::MemberEventContent, name::NameEventContent, + power_levels::PowerLevelsEventContent, third_party_invite::ThirdPartyInviteEventContent, + topic::TopicEventContent, +}; use EventType; /// A stripped-down version of a state event that is included along with some other events. @@ -265,8 +260,7 @@ mod tests { use serde_json::{from_str, to_string}; use super::{StrippedRoomTopic, StrippedState}; - use room::join_rules::JoinRule; - use room::topic::TopicEventContent; + use room::{join_rules::JoinRule, topic::TopicEventContent}; use EventType; #[test] From 1b2cd339cb6b10659d2838022e739802b2b6bee7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 13 Jan 2019 22:01:27 +0100 Subject: [PATCH 2/2] Update to Rust 2018 --- Cargo.toml | 1 + src/call/answer.rs | 2 ++ src/call/candidates.rs | 2 ++ src/call/hangup.rs | 2 ++ src/call/invite.rs | 2 ++ src/call/mod.rs | 2 ++ src/collections/all.rs | 37 +++++++++++++++++----------------- src/collections/only.rs | 22 ++++++++++---------- src/direct.rs | 1 + src/lib.rs | 12 +++-------- src/macros.rs | 14 ++++++------- src/presence.rs | 2 ++ src/receipt.rs | 1 + src/room/aliases.rs | 1 + src/room/avatar.rs | 2 ++ src/room/canonical_alias.rs | 1 + src/room/create.rs | 1 + src/room/guest_access.rs | 2 ++ src/room/history_visibility.rs | 2 ++ src/room/join_rules.rs | 2 ++ src/room/member.rs | 5 +++-- src/room/message.rs | 1 + src/room/mod.rs | 2 ++ src/room/name.rs | 2 ++ src/room/pinned_events.rs | 10 ++++----- src/room/power_levels.rs | 3 ++- src/room/redaction.rs | 1 + src/room/third_party_invite.rs | 2 ++ src/room/topic.rs | 2 ++ src/stripped.rs | 25 ++++++++++++++--------- src/tag.rs | 2 ++ src/typing.rs | 1 + 32 files changed, 103 insertions(+), 64 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25285a25..8b14cc3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ name = "ruma-events" readme = "README.md" repository = "https://github.com/ruma/ruma-events" version = "0.11.0" +edition = "2018" [dependencies] ruma-identifiers = "0.11.0" diff --git a/src/call/answer.rs b/src/call/answer.rs index 7ec22242..a756953d 100644 --- a/src/call/answer.rs +++ b/src/call/answer.rs @@ -1,5 +1,7 @@ //! Types for the *m.call.answer* event. +use serde_derive::{Deserialize, Serialize}; + use super::SessionDescription; room_event! { diff --git a/src/call/candidates.rs b/src/call/candidates.rs index 352ca046..ff777423 100644 --- a/src/call/candidates.rs +++ b/src/call/candidates.rs @@ -1,5 +1,7 @@ //! Types for the *m.call.candidates* event. +use serde_derive::{Deserialize, Serialize}; + room_event! { /// This event is sent by callers after sending an invite and by the callee after answering. /// Its purpose is to give the other party additional ICE candidates to try using to diff --git a/src/call/hangup.rs b/src/call/hangup.rs index 6546f56c..73ab4892 100644 --- a/src/call/hangup.rs +++ b/src/call/hangup.rs @@ -1,5 +1,7 @@ //! Types for the *m.call.hangup* event. +use serde_derive::{Deserialize, Serialize}; + room_event! { /// Sent by either party to signal their termination of the call. This can be sent either once /// the call has has been established or before to abort the call. diff --git a/src/call/invite.rs b/src/call/invite.rs index 5493a836..05b73eb8 100644 --- a/src/call/invite.rs +++ b/src/call/invite.rs @@ -1,5 +1,7 @@ //! Types for the *m.call.invite* event. +use serde_derive::{Deserialize, Serialize}; + use super::SessionDescription; room_event! { diff --git a/src/call/mod.rs b/src/call/mod.rs index 90cb4624..47ad932c 100644 --- a/src/call/mod.rs +++ b/src/call/mod.rs @@ -2,6 +2,8 @@ //! //! This module also contains types shared by events in its child namespaces. +use serde_derive::{Deserialize, Serialize}; + pub mod answer; pub mod candidates; pub mod hangup; diff --git a/src/collections/all.rs b/src/collections/all.rs index e3f03c9d..6347d9bd 100644 --- a/src/collections/all.rs +++ b/src/collections/all.rs @@ -1,26 +1,25 @@ //! Enums for heterogeneous collections of events, inclusive for every event type that implements //! the trait of the same name. -use call::{ - answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, +use crate::{ + call::{ + answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, + }, + direct::DirectEvent, + presence::PresenceEvent, + receipt::ReceiptEvent, + room::{ + aliases::AliasesEvent, avatar::AvatarEvent, canonical_alias::CanonicalAliasEvent, + create::CreateEvent, guest_access::GuestAccessEvent, + history_visibility::HistoryVisibilityEvent, join_rules::JoinRulesEvent, + member::MemberEvent, message::MessageEvent, name::NameEvent, + pinned_events::PinnedEventsEvent, power_levels::PowerLevelsEvent, + redaction::RedactionEvent, third_party_invite::ThirdPartyInviteEvent, topic::TopicEvent, + }, + tag::TagEvent, + typing::TypingEvent, + CustomEvent, CustomRoomEvent, CustomStateEvent, EventType, }; -use direct::DirectEvent; -use presence::PresenceEvent; -use receipt::ReceiptEvent; -use room::{ - aliases::AliasesEvent, avatar::AvatarEvent, canonical_alias::CanonicalAliasEvent, - create::CreateEvent, guest_access::GuestAccessEvent, - history_visibility::HistoryVisibilityEvent, join_rules::JoinRulesEvent, member::MemberEvent, - message::MessageEvent, name::NameEvent, pinned_events::PinnedEventsEvent, - power_levels::PowerLevelsEvent, redaction::RedactionEvent, - third_party_invite::ThirdPartyInviteEvent, topic::TopicEvent, -}; -use tag::TagEvent; -use typing::TypingEvent; -use CustomEvent; -use CustomRoomEvent; -use CustomStateEvent; -use EventType; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; diff --git a/src/collections/only.rs b/src/collections/only.rs index 1ea1d9ca..e3091d2e 100644 --- a/src/collections/only.rs +++ b/src/collections/only.rs @@ -5,18 +5,18 @@ use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; pub use super::all::StateEvent; -use call::{ - answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, +use crate::{ + call::{ + answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, + }, + direct::DirectEvent, + presence::PresenceEvent, + receipt::ReceiptEvent, + room::{message::MessageEvent, redaction::RedactionEvent}, + tag::TagEvent, + typing::TypingEvent, + CustomEvent, CustomRoomEvent, EventType, }; -use direct::DirectEvent; -use presence::PresenceEvent; -use receipt::ReceiptEvent; -use room::{message::MessageEvent, redaction::RedactionEvent}; -use tag::TagEvent; -use typing::TypingEvent; -use CustomEvent; -use CustomRoomEvent; -use EventType; /// A basic event. #[derive(Clone, Debug)] diff --git a/src/direct.rs b/src/direct.rs index 8f3d1362..4089c1f1 100644 --- a/src/direct.rs +++ b/src/direct.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; event! { /// Informs the client about the rooms that are considered direct by a user. diff --git a/src/lib.rs b/src/lib.rs index 3be19fde..df16676c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,13 +100,6 @@ #![deny(missing_docs)] #![deny(warnings)] -extern crate ruma_identifiers; -extern crate ruma_signatures; -extern crate serde; -#[macro_use] -extern crate serde_derive; -extern crate serde_json; - use std::fmt::{Debug, Display, Error as FmtError, Formatter, Result as FmtResult}; use ruma_identifiers::{EventId, RoomId, UserId}; @@ -114,6 +107,7 @@ use serde::{ de::{Error as SerdeError, Visitor}, Deserialize, Deserializer, Serialize, Serializer, }; +use serde_derive::{Deserialize, Serialize}; use serde_json::Value; #[macro_use] @@ -253,7 +247,7 @@ state_event! { } impl Display for EventType { - fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { let event_type_str = match *self { EventType::CallAnswer => "m.call.answer", EventType::CallCandidates => "m.call.candidates", @@ -337,7 +331,7 @@ impl<'de> Deserialize<'de> for EventType { impl<'de> Visitor<'de> for EventTypeVisitor { type Value = EventType; - fn expecting(&self, formatter: &mut Formatter) -> FmtResult { + fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult { write!(formatter, "a Matrix event type as a string") } diff --git a/src/macros.rs b/src/macros.rs index 828cdbc2..ae98972e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,7 +1,7 @@ macro_rules! impl_enum { ($name:ident { $($variant:ident => $s:expr,)+ }) => { impl ::std::fmt::Display for $name { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> { let variant = match *self { $($name::$variant => $s,)* }; @@ -39,7 +39,7 @@ macro_rules! event { pub content: $content_type, /// The type of the event. - #[serde(rename="type")] + #[serde(rename = "type")] pub event_type: $crate::EventType, $( @@ -87,7 +87,7 @@ macro_rules! room_event { pub event_id: ::ruma_identifiers::EventId, /// The type of the event. - #[serde(rename="type")] + #[serde(rename = "type")] pub event_type: $crate::EventType, /// Timestamp in milliseconds on originating homeserver when this event was sent. @@ -98,7 +98,7 @@ macro_rules! room_event { pub room_id: Option<::ruma_identifiers::RoomId>, /// Additional key-value pairs not signed by the homeserver. - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub unsigned: Option<::serde_json::Value>, /// The unique identifier for the user who sent this event. @@ -162,14 +162,14 @@ macro_rules! state_event { pub event_id: ::ruma_identifiers::EventId, /// The type of the event. - #[serde(rename="type")] + #[serde(rename = "type")] pub event_type: $crate::EventType, /// Timestamp in milliseconds on originating homeserver when this event was sent. pub origin_server_ts: u64, /// The previous content for this state key, if any. - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub prev_content: Option<$content_type>, /// The unique identifier for the room associated with this event. @@ -180,7 +180,7 @@ macro_rules! state_event { pub state_key: String, /// Additional key-value pairs not signed by the homeserver. - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub unsigned: Option<::serde_json::Value>, /// The unique identifier for the user associated with this event. diff --git a/src/presence.rs b/src/presence.rs index 44b3d64f..cfbef4c2 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -1,5 +1,7 @@ //! Types for the *m.presence* event. +use serde_derive::{Deserialize, Serialize}; + use ruma_identifiers::UserId; event! { diff --git a/src/receipt.rs b/src/receipt.rs index 06902af5..de9acae9 100644 --- a/src/receipt.rs +++ b/src/receipt.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use ruma_identifiers::{EventId, RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; event! { /// Informs the client of new receipts. diff --git a/src/room/aliases.rs b/src/room/aliases.rs index 6678d03d..4cdee7e0 100644 --- a/src/room/aliases.rs +++ b/src/room/aliases.rs @@ -1,6 +1,7 @@ //! Types for the *m.room.aliases* event. use ruma_identifiers::RoomAliasId; +use serde_derive::{Deserialize, Serialize}; state_event! { /// Informs the room about what room aliases it has been given. diff --git a/src/room/avatar.rs b/src/room/avatar.rs index 69e3622c..203269c3 100644 --- a/src/room/avatar.rs +++ b/src/room/avatar.rs @@ -1,5 +1,7 @@ //! Types for the *m.room.avatar* event. +use serde_derive::{Deserialize, Serialize}; + use super::ImageInfo; state_event! { diff --git a/src/room/canonical_alias.rs b/src/room/canonical_alias.rs index f2dd2677..23010529 100644 --- a/src/room/canonical_alias.rs +++ b/src/room/canonical_alias.rs @@ -1,6 +1,7 @@ //! Types for the *m.room.canonical_alias* event. use ruma_identifiers::RoomAliasId; +use serde_derive::{Deserialize, Serialize}; state_event! { /// Informs the room as to which alias is the canonical one. diff --git a/src/room/create.rs b/src/room/create.rs index 26dd7387..c19a1847 100644 --- a/src/room/create.rs +++ b/src/room/create.rs @@ -1,6 +1,7 @@ //! Types for the *m.room.create* event. use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; state_event! { /// This is the first event in a room and cannot be changed. It acts as the root of all other diff --git a/src/room/guest_access.rs b/src/room/guest_access.rs index 2f030cab..e865a684 100644 --- a/src/room/guest_access.rs +++ b/src/room/guest_access.rs @@ -1,5 +1,7 @@ //! Types for the *m.room.guest_access* event. +use serde_derive::{Deserialize, Serialize}; + state_event! { /// Controls whether guest users are allowed to join rooms. /// diff --git a/src/room/history_visibility.rs b/src/room/history_visibility.rs index 7c1b52fc..ace8661b 100644 --- a/src/room/history_visibility.rs +++ b/src/room/history_visibility.rs @@ -1,5 +1,7 @@ //! Types for the *m.room.history_visibility* event. +use serde_derive::{Deserialize, Serialize}; + state_event! { /// This event controls whether a member of a room can see the events that happened in a room /// from before they joined. diff --git a/src/room/join_rules.rs b/src/room/join_rules.rs index 84cdfa2d..6546482d 100644 --- a/src/room/join_rules.rs +++ b/src/room/join_rules.rs @@ -1,5 +1,7 @@ //! Types for the *m.room.join_rules* event. +use serde_derive::{Deserialize, Serialize}; + state_event! { /// Describes how users are allowed to join the room. pub struct JoinRulesEvent(JoinRulesEventContent) {} diff --git a/src/room/member.rs b/src/room/member.rs index 32ca524e..a3258bcd 100644 --- a/src/room/member.rs +++ b/src/room/member.rs @@ -2,8 +2,9 @@ use ruma_identifiers::UserId; use ruma_signatures::Signatures; +use serde_derive::{Deserialize, Serialize}; -use stripped::StrippedState; +use crate::stripped::StrippedState; state_event! { /// The current membership state of a user in the room. @@ -22,7 +23,7 @@ state_event! { /// on a few select state events such as the room name. pub struct MemberEvent(MemberEventContent) { /// A subset of the state of the room at the time of the invite. - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub invite_room_state: Option> } } diff --git a/src/room/message.rs b/src/room/message.rs index e4763d8a..66c1d1ac 100644 --- a/src/room/message.rs +++ b/src/room/message.rs @@ -1,6 +1,7 @@ //! Types for the *m.room.message* event. use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; +use serde_derive::{Deserialize, Serialize}; use serde_json::{from_value, Value}; use super::{ImageInfo, ThumbnailInfo}; diff --git a/src/room/mod.rs b/src/room/mod.rs index ee9015b5..be511380 100644 --- a/src/room/mod.rs +++ b/src/room/mod.rs @@ -2,6 +2,8 @@ //! //! This module also contains types shared by events in its child namespaces. +use serde_derive::{Deserialize, Serialize}; + pub mod aliases; pub mod avatar; pub mod canonical_alias; diff --git a/src/room/name.rs b/src/room/name.rs index 5c497fb4..d744a425 100644 --- a/src/room/name.rs +++ b/src/room/name.rs @@ -1,5 +1,7 @@ //! Types for the *m.room.name* event. +use serde_derive::{Deserialize, Serialize}; + state_event! { /// A human-friendly room name designed to be displayed to the end-user. pub struct NameEvent(NameEventContent) {} diff --git a/src/room/pinned_events.rs b/src/room/pinned_events.rs index 3059e92f..2ed59e9d 100644 --- a/src/room/pinned_events.rs +++ b/src/room/pinned_events.rs @@ -1,6 +1,7 @@ //! Types for the *m.room.pinned_events* event. use ruma_identifiers::EventId; +use serde_derive::{Deserialize, Serialize}; state_event! { /// Used to "pin" particular events in a room for other participants to review later. @@ -19,11 +20,10 @@ mod tests { use ruma_identifiers::{EventId, RoomId, UserId}; use serde_json::{from_str, to_string}; - use room::pinned_events::{PinnedEventsContent, PinnedEventsEvent}; - use Event; - use EventType; - use RoomEvent; - use StateEvent; + use crate::{ + room::pinned_events::{PinnedEventsContent, PinnedEventsEvent}, + Event, EventType, RoomEvent, StateEvent, + }; #[test] fn serialization_deserialization() { diff --git a/src/room/power_levels.rs b/src/room/power_levels.rs index 09b116d7..04ba4d61 100644 --- a/src/room/power_levels.rs +++ b/src/room/power_levels.rs @@ -3,8 +3,9 @@ use std::collections::HashMap; use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; -use EventType; +use crate::EventType; state_event! { /// Defines the power levels (privileges) of users in the room. diff --git a/src/room/redaction.rs b/src/room/redaction.rs index 99224565..a300b2ce 100644 --- a/src/room/redaction.rs +++ b/src/room/redaction.rs @@ -1,6 +1,7 @@ //! Types for the *m.room.redaction* event. use ruma_identifiers::EventId; +use serde_derive::{Deserialize, Serialize}; room_event! { /// A redaction of an event. diff --git a/src/room/third_party_invite.rs b/src/room/third_party_invite.rs index a2e2abbd..865aec91 100644 --- a/src/room/third_party_invite.rs +++ b/src/room/third_party_invite.rs @@ -1,5 +1,7 @@ //! Types for the *m.room.third_party_invite* event. +use serde_derive::{Deserialize, Serialize}; + state_event! { /// An invitation to a room issued to a third party identifier, rather than a matrix user ID. /// diff --git a/src/room/topic.rs b/src/room/topic.rs index 5ca043ad..559a84e9 100644 --- a/src/room/topic.rs +++ b/src/room/topic.rs @@ -1,5 +1,7 @@ //! Types for the *m.room.topic* event. +use serde_derive::{Deserialize, Serialize}; + state_event! { /// A topic is a short message detailing what is currently being discussed in the room. pub struct TopicEvent(TopicEventContent) {} diff --git a/src/stripped.rs b/src/stripped.rs index b852e0f5..37f05b21 100644 --- a/src/stripped.rs +++ b/src/stripped.rs @@ -7,17 +7,20 @@ use ruma_identifiers::UserId; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; +use serde_derive::{Deserialize, Serialize}; use serde_json::{from_value, Value}; -use room::{ - aliases::AliasesEventContent, avatar::AvatarEventContent, - canonical_alias::CanonicalAliasEventContent, create::CreateEventContent, - guest_access::GuestAccessEventContent, history_visibility::HistoryVisibilityEventContent, - join_rules::JoinRulesEventContent, member::MemberEventContent, name::NameEventContent, - power_levels::PowerLevelsEventContent, third_party_invite::ThirdPartyInviteEventContent, - topic::TopicEventContent, +use crate::{ + room::{ + aliases::AliasesEventContent, avatar::AvatarEventContent, + canonical_alias::CanonicalAliasEventContent, create::CreateEventContent, + guest_access::GuestAccessEventContent, history_visibility::HistoryVisibilityEventContent, + join_rules::JoinRulesEventContent, member::MemberEventContent, name::NameEventContent, + power_levels::PowerLevelsEventContent, third_party_invite::ThirdPartyInviteEventContent, + topic::TopicEventContent, + }, + EventType, }; -use EventType; /// A stripped-down version of a state event that is included along with some other events. #[derive(Clone, Debug)] @@ -260,8 +263,10 @@ mod tests { use serde_json::{from_str, to_string}; use super::{StrippedRoomTopic, StrippedState}; - use room::{join_rules::JoinRule, topic::TopicEventContent}; - use EventType; + use crate::{ + room::{join_rules::JoinRule, topic::TopicEventContent}, + EventType, + }; #[test] fn serialize_stripped_state_event() { diff --git a/src/tag.rs b/src/tag.rs index b0eb53f1..d3d83bfa 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -2,6 +2,8 @@ use std::collections::HashMap; +use serde_derive::{Deserialize, Serialize}; + event! { /// Informs the client of tags on a room. pub struct TagEvent(TagEventContent) {} diff --git a/src/typing.rs b/src/typing.rs index 4e66782f..e9e3e85f 100644 --- a/src/typing.rs +++ b/src/typing.rs @@ -1,6 +1,7 @@ //! Types for the *m.typing* event. use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; event! { /// Informs the client of the list of users currently typing.