Use nested imports, misc. import changes

* Bring imports into a consistent order (std, crates, internal)
* Replace super::super-imports by crate-relative ones
This commit is contained in:
Jonas Platte 2019-01-13 21:58:34 +01:00
parent 179a06040d
commit 6f093f70ed
8 changed files with 64 additions and 81 deletions

1
.rustfmt.toml Normal file
View File

@ -0,0 +1 @@
merge_imports = true

View File

@ -1,34 +1,28 @@
//! Enums for heterogeneous collections of events, inclusive for every event type that implements //! Enums for heterogeneous collections of events, inclusive for every event type that implements
//! the trait of the same name. //! the trait of the same name.
use call::answer::AnswerEvent; use call::{
use call::candidates::CandidatesEvent; answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent,
use call::hangup::HangupEvent; };
use call::invite::InviteEvent;
use direct::DirectEvent; use direct::DirectEvent;
use presence::PresenceEvent; use presence::PresenceEvent;
use receipt::ReceiptEvent; use receipt::ReceiptEvent;
use room::aliases::AliasesEvent; use room::{
use room::avatar::AvatarEvent; aliases::AliasesEvent, avatar::AvatarEvent, canonical_alias::CanonicalAliasEvent,
use room::canonical_alias::CanonicalAliasEvent; create::CreateEvent, guest_access::GuestAccessEvent,
use room::create::CreateEvent; history_visibility::HistoryVisibilityEvent, join_rules::JoinRulesEvent, member::MemberEvent,
use room::guest_access::GuestAccessEvent; message::MessageEvent, name::NameEvent, pinned_events::PinnedEventsEvent,
use room::history_visibility::HistoryVisibilityEvent; power_levels::PowerLevelsEvent, redaction::RedactionEvent,
use room::join_rules::JoinRulesEvent; third_party_invite::ThirdPartyInviteEvent, topic::TopicEvent,
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 tag::TagEvent; use tag::TagEvent;
use typing::TypingEvent; use typing::TypingEvent;
use {CustomEvent, CustomRoomEvent, CustomStateEvent, EventType}; use CustomEvent;
use CustomRoomEvent;
use CustomStateEvent;
use EventType;
use serde::de::Error; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{from_value, Value}; use serde_json::{from_value, Value};
/// A basic event, room event, or state event. /// A basic event, room event, or state event.
@ -425,7 +419,8 @@ impl<'de> Deserialize<'de> for Event {
}; };
Ok(Event::CustomState(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() && value.get("sender").is_some()
{ {
let event = match from_value::<CustomRoomEvent>(value) { let event = match from_value::<CustomRoomEvent>(value) {

View File

@ -1,24 +1,22 @@
//! Enums for heterogeneous collections of events, exclusive to event types that implement "at //! Enums for heterogeneous collections of events, exclusive to event types that implement "at
//! most" the trait of the same name. //! most" the trait of the same name.
use call::answer::AnswerEvent; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
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_json::{from_value, Value}; use serde_json::{from_value, Value};
pub use super::all::StateEvent; 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. /// A basic event.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View File

@ -22,9 +22,11 @@ mod tests {
use ruma_identifiers::{RoomId, UserId}; use ruma_identifiers::{RoomId, UserId};
use serde_json::{from_str, to_string}; use serde_json::{from_str, to_string};
use super::super::EventType; use crate::{
use collections; collections,
use direct::{DirectEvent, DirectEventContent}; direct::{DirectEvent, DirectEventContent},
EventType,
};
#[test] #[test]
fn serialization() { fn serialization() {

View File

@ -110,8 +110,10 @@ extern crate serde_json;
use std::fmt::{Debug, Display, Error as FmtError, Formatter, Result as FmtResult}; use std::fmt::{Debug, Display, Error as FmtError, Formatter, Result as FmtResult};
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
use serde::de::{Error as SerdeError, Visitor}; use serde::{
use serde::{Deserialize, Deserializer, Serialize, Serializer}; de::{Error as SerdeError, Visitor},
Deserialize, Deserializer, Serialize, Serializer,
};
use serde_json::Value; use serde_json::Value;
#[macro_use] #[macro_use]

View File

@ -59,12 +59,13 @@ impl_enum! {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json::{from_str, to_string};
use std::convert::TryFrom; use std::convert::TryFrom;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde_json::{from_str, to_string};
use super::{PresenceEvent, PresenceEventContent, PresenceState}; use super::{PresenceEvent, PresenceEventContent, PresenceState};
use super::super::{EventType}; use crate::EventType;
/// Test serialization and deserialization of example m.presence event from the spec /// 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 /// https://github.com/turt2live/matrix-doc/blob/master/event-schemas/examples/m.presence
@ -84,18 +85,9 @@ mod tests {
let serialized_event = 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"}"#; r#"{"content":{"avatar_url":"mxc://localhost:wefuiwegh8742w","currently_active":false,"last_active_ago":2478593,"presence":"online"},"type":"m.presence","sender":"@example:localhost"}"#;
assert_eq!( assert_eq!(to_string(&event).unwrap(), serialized_event);
to_string(&event).unwrap(),
serialized_event
);
let deserialized_event = from_str::<PresenceEvent>(serialized_event).unwrap(); let deserialized_event = from_str::<PresenceEvent>(serialized_event).unwrap();
assert_eq!( assert_eq!(deserialized_event.content, event.content);
deserialized_event.content, assert_eq!(deserialized_event.sender, event.sender);
event.content
);
assert_eq!(
deserialized_event.sender,
event.sender
);
} }
} }

View File

@ -1,7 +1,6 @@
//! Types for the *m.room.message* event. //! Types for the *m.room.message* event.
use serde::de::Error; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{from_value, Value}; use serde_json::{from_value, Value};
use super::{ImageInfo, ThumbnailInfo}; use super::{ImageInfo, ThumbnailInfo};
@ -396,17 +395,17 @@ mod tests {
assert_eq!( assert_eq!(
from_str::<MessageEventContent>( from_str::<MessageEventContent>(
r#"{"body":"test","msgtype":"m.audio","url":"http://example.com/audio.mp3"}"# r#"{"body":"test","msgtype":"m.audio","url":"http://example.com/audio.mp3"}"#
).unwrap(), )
.unwrap(),
message_event_content message_event_content
); );
} }
#[test] #[test]
fn deserialization_failure() { fn deserialization_failure() {
assert!( assert!(from_str::<MessageEventContent>(
from_str::<MessageEventContent>( r#"{"body":"test","msgtype":"m.location","url":"http://example.com/audio.mp3"}"#
r#"{"body":"test","msgtype":"m.location","url":"http://example.com/audio.mp3"}"# )
).is_err() .is_err());
);
} }
} }

View File

@ -6,22 +6,17 @@
//! the other fields are otherwise inapplicable. //! the other fields are otherwise inapplicable.
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde::de::Error; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{from_value, Value}; use serde_json::{from_value, Value};
use room::aliases::AliasesEventContent; use room::{
use room::avatar::AvatarEventContent; aliases::AliasesEventContent, avatar::AvatarEventContent,
use room::canonical_alias::CanonicalAliasEventContent; canonical_alias::CanonicalAliasEventContent, create::CreateEventContent,
use room::create::CreateEventContent; guest_access::GuestAccessEventContent, history_visibility::HistoryVisibilityEventContent,
use room::guest_access::GuestAccessEventContent; join_rules::JoinRulesEventContent, member::MemberEventContent, name::NameEventContent,
use room::history_visibility::HistoryVisibilityEventContent; power_levels::PowerLevelsEventContent, third_party_invite::ThirdPartyInviteEventContent,
use room::join_rules::JoinRulesEventContent; topic::TopicEventContent,
use room::member::MemberEventContent; };
use room::name::NameEventContent;
use room::power_levels::PowerLevelsEventContent;
use room::third_party_invite::ThirdPartyInviteEventContent;
use room::topic::TopicEventContent;
use EventType; use EventType;
/// A stripped-down version of a state event that is included along with some other events. /// 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 serde_json::{from_str, to_string};
use super::{StrippedRoomTopic, StrippedState}; use super::{StrippedRoomTopic, StrippedState};
use room::join_rules::JoinRule; use room::{join_rules::JoinRule, topic::TopicEventContent};
use room::topic::TopicEventContent;
use EventType; use EventType;
#[test] #[test]