From 8e10064364e9b7c7c67a2ca4c44abc2cfc9599f6 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 22 Aug 2023 10:55:18 +0200 Subject: [PATCH] Enforce import grouping Includes a few manual changes to make rustfmt behave a bit better. --- .rustfmt.toml | 1 + crates/ruma-client-api/src/filter.rs | 3 +- .../src/keys/upload_signatures.rs | 3 +- .../src/sync/sync_events/v3.rs | 2 +- .../src/sync/sync_events/v4.rs | 3 +- crates/ruma-client-api/src/uiaa/user_serde.rs | 3 +- crates/ruma-common/src/api.rs | 154 +++++++++--------- crates/ruma-common/src/canonical_json.rs | 3 +- crates/ruma-common/src/events/content.rs | 3 +- crates/ruma-common/src/events/direct.rs | 2 +- crates/ruma-common/src/events/poll.rs | 3 +- .../ruma-common/src/events/poll/response.rs | 3 +- crates/ruma-common/src/events/poll/start.rs | 11 +- .../src/events/poll/unstable_response.rs | 3 +- .../src/events/poll/unstable_start.rs | 3 +- .../unstable_poll_answers_serde.rs | 3 +- crates/ruma-common/src/events/room.rs | 3 +- .../src/events/room/message/reply.rs | 3 +- .../src/events/room/thumbnail_source_serde.rs | 3 +- crates/ruma-common/src/events/room_key.rs | 2 +- .../src/events/secret_storage/secret.rs | 3 +- crates/ruma-common/src/events/tag.rs | 3 +- crates/ruma-common/src/identifiers.rs | 10 +- .../src/push/condition/flattened_json.rs | 3 +- .../push/condition/push_condition_serde.rs | 3 +- crates/ruma-common/tests/events/enums.rs | 27 ++- .../tests/events/ephemeral_event.rs | 15 +- .../ruma-macros/src/events/event_content.rs | 3 +- crates/ruma-server-util/src/authorization.rs | 1 - crates/ruma-signatures/src/keys.rs | 3 +- crates/ruma-signatures/src/lib.rs | 16 +- crates/ruma-state-res/src/test_utils.rs | 3 +- crates/ruma/src/lib.rs | 9 +- 33 files changed, 149 insertions(+), 164 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 7158a819..ed1837cc 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,6 +1,7 @@ comment_width = 100 format_code_in_doc_comments = true imports_granularity = "Crate" +group_imports = "StdExternalCrate" newline_style = "Unix" use_field_init_shorthand = true use_small_heuristics = "Max" diff --git a/crates/ruma-client-api/src/filter.rs b/crates/ruma-client-api/src/filter.rs index c70808e0..fa69ee1d 100644 --- a/crates/ruma-client-api/src/filter.rs +++ b/crates/ruma-client-api/src/filter.rs @@ -10,9 +10,8 @@ use js_int::UInt; use ruma_common::{serde::StringEnum, OwnedRoomId, OwnedUserId}; use serde::{Deserialize, Serialize}; -use crate::PrivOwnedStr; - pub use self::{lazy_load::LazyLoadOptions, url::UrlFilter}; +use crate::PrivOwnedStr; /// Format to use for returned events. #[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))] diff --git a/crates/ruma-client-api/src/keys/upload_signatures.rs b/crates/ruma-client-api/src/keys/upload_signatures.rs index 3b2a46b1..5d52bfd5 100644 --- a/crates/ruma-client-api/src/keys/upload_signatures.rs +++ b/crates/ruma-client-api/src/keys/upload_signatures.rs @@ -19,9 +19,8 @@ pub mod v3 { use serde::{Deserialize, Serialize}; use serde_json::value::RawValue as RawJsonValue; - use crate::PrivOwnedStr; - pub use super::iter::SignedKeysIter; + use crate::PrivOwnedStr; const METADATA: Metadata = metadata! { method: POST, diff --git a/crates/ruma-client-api/src/sync/sync_events/v3.rs b/crates/ruma-client-api/src/sync/sync_events/v3.rs index 5db95f8f..1b71eea9 100644 --- a/crates/ruma-client-api/src/sync/sync_events/v3.rs +++ b/crates/ruma-client-api/src/sync/sync_events/v3.rs @@ -4,7 +4,6 @@ use std::{collections::BTreeMap, time::Duration}; -use super::{DeviceLists, UnreadNotificationsCount}; use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, @@ -20,6 +19,7 @@ use ruma_common::{ }; use serde::{Deserialize, Serialize}; +use super::{DeviceLists, UnreadNotificationsCount}; use crate::filter::FilterDefinition; const METADATA: Metadata = metadata! { diff --git a/crates/ruma-client-api/src/sync/sync_events/v4.rs b/crates/ruma-client-api/src/sync/sync_events/v4.rs index 8767658e..5182956d 100644 --- a/crates/ruma-client-api/src/sync/sync_events/v4.rs +++ b/crates/ruma-client-api/src/sync/sync_events/v4.rs @@ -6,7 +6,6 @@ use std::{collections::BTreeMap, time::Duration}; -use super::{DeviceLists, UnreadNotificationsCount}; use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, @@ -21,6 +20,8 @@ use ruma_common::{ }; use serde::{Deserialize, Serialize}; +use super::{DeviceLists, UnreadNotificationsCount}; + const METADATA: Metadata = metadata! { method: POST, rate_limited: false, diff --git a/crates/ruma-client-api/src/uiaa/user_serde.rs b/crates/ruma-client-api/src/uiaa/user_serde.rs index 4ce927e5..ac83818d 100644 --- a/crates/ruma-client-api/src/uiaa/user_serde.rs +++ b/crates/ruma-client-api/src/uiaa/user_serde.rs @@ -104,10 +104,11 @@ impl<'de> Deserialize<'de> for UserIdentifier { #[cfg(test)] mod tests { - use crate::uiaa::UserIdentifier; use assert_matches2::assert_matches; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; + use crate::uiaa::UserIdentifier; + #[test] fn serialize() { assert_eq!( diff --git a/crates/ruma-common/src/api.rs b/crates/ruma-common/src/api.rs index 5cb7f22a..d766bfcb 100644 --- a/crates/ruma-common/src/api.rs +++ b/crates/ruma-common/src/api.rs @@ -17,8 +17,83 @@ use std::{convert::TryInto as _, error::Error as StdError}; use bytes::BufMut; use serde::{Deserialize, Serialize}; +use self::error::{FromHttpRequestError, FromHttpResponseError, IntoHttpError}; use crate::UserId; +/// Convenient constructor for [`Metadata`] constants. +/// +/// Usage: +/// +/// ``` +/// # use ruma_common::{metadata, api::Metadata}; +/// const _: Metadata = metadata! { +/// method: GET, // one of the associated constants of http::Method +/// rate_limited: true, +/// authentication: AccessToken, // one of the variants of api::AuthScheme +/// +/// // history of endpoint paths +/// // there must be at least one path but otherwise everything is optional +/// history: { +/// unstable => "/_matrix/foo/org.bar.msc9000/baz", +/// unstable => "/_matrix/foo/org.bar.msc9000/qux", +/// 1.0 => "/_matrix/media/r0/qux", +/// 1.1 => "/_matrix/media/v3/qux", +/// 1.2 => deprecated, +/// 1.3 => removed, +/// } +/// }; +/// ``` +#[macro_export] +macro_rules! metadata { + ( $( $field:ident: $rhs:tt ),+ $(,)? ) => { + $crate::api::Metadata { + $( $field: $crate::metadata!(@field $field: $rhs) ),+ + } + }; + + ( @field method: $method:ident ) => { $crate::exports::http::Method::$method }; + + ( @field authentication: $scheme:ident ) => { $crate::api::AuthScheme::$scheme }; + + ( @field history: { + $( unstable => $unstable_path:literal, )* + $( $( $version:literal => $rhs:tt, )+ )? + } ) => { + $crate::metadata! { + @history_impl + [ $($unstable_path),* ] + // Flip left and right to avoid macro parsing ambiguities + $( $( $rhs = $version ),+ )? + } + }; + + // Simple literal case: used for description, name, rate_limited + ( @field $_field:ident: $rhs:expr ) => { $rhs }; + + ( @history_impl + [ $($unstable_path:literal),* ] + $( + $( $stable_path:literal = $version:literal ),+ + $(, + deprecated = $deprecated_version:literal + $(, removed = $removed_version:literal )? + )? + )? + ) => { + $crate::api::VersionHistory::new( + &[ $( $unstable_path ),* ], + &[ $($( + ($crate::api::MatrixVersion::from_lit(stringify!($version)), $stable_path) + ),+)? ], + $crate::metadata!(@optional_version $($( $deprecated_version )?)?), + $crate::metadata!(@optional_version $($($( $removed_version )?)?)?), + ) + }; + + ( @optional_version ) => { None }; + ( @optional_version $version:literal ) => { Some($crate::api::MatrixVersion::from_lit(stringify!($version))) } +} + /// Generates [`OutgoingRequest`] and [`IncomingRequest`] implementations. /// /// The `OutgoingRequest` impl is on the `Request` type this attribute is used on. It is @@ -134,7 +209,6 @@ use crate::UserId; /// } /// ``` pub use ruma_macros::request; - /// Generates [`OutgoingResponse`] and [`IncomingResponse`] implementations. /// /// The `OutgoingRequest` impl is feature-gated behind `cfg(feature = "client")`. @@ -230,9 +304,7 @@ pub use ruma_macros::response; pub mod error; mod metadata; -pub use metadata::{MatrixVersion, Metadata, VersionHistory, VersioningDecision}; - -use error::{FromHttpRequestError, FromHttpResponseError, IntoHttpError}; +pub use self::metadata::{MatrixVersion, Metadata, VersionHistory, VersioningDecision}; /// An enum to control whether an access token should be added to outgoing requests #[derive(Clone, Copy, Debug)] @@ -435,77 +507,3 @@ pub enum Direction { #[serde(rename = "f")] Forward, } - -/// Convenient constructor for [`Metadata`] constants. -/// -/// Usage: -/// -/// ``` -/// # use ruma_common::{metadata, api::Metadata}; -/// const _: Metadata = metadata! { -/// method: GET, // one of the associated constants of http::Method -/// rate_limited: true, -/// authentication: AccessToken, // one of the variants of api::AuthScheme -/// -/// // history of endpoint paths -/// // there must be at least one path but otherwise everything is optional -/// history: { -/// unstable => "/_matrix/foo/org.bar.msc9000/baz", -/// unstable => "/_matrix/foo/org.bar.msc9000/qux", -/// 1.0 => "/_matrix/media/r0/qux", -/// 1.1 => "/_matrix/media/v3/qux", -/// 1.2 => deprecated, -/// 1.3 => removed, -/// } -/// }; -/// ``` -#[macro_export] -macro_rules! metadata { - ( $( $field:ident: $rhs:tt ),+ $(,)? ) => { - $crate::api::Metadata { - $( $field: $crate::metadata!(@field $field: $rhs) ),+ - } - }; - - ( @field method: $method:ident ) => { $crate::exports::http::Method::$method }; - - ( @field authentication: $scheme:ident ) => { $crate::api::AuthScheme::$scheme }; - - ( @field history: { - $( unstable => $unstable_path:literal, )* - $( $( $version:literal => $rhs:tt, )+ )? - } ) => { - $crate::metadata! { - @history_impl - [ $($unstable_path),* ] - // Flip left and right to avoid macro parsing ambiguities - $( $( $rhs = $version ),+ )? - } - }; - - // Simple literal case: used for description, name, rate_limited - ( @field $_field:ident: $rhs:expr ) => { $rhs }; - - ( @history_impl - [ $($unstable_path:literal),* ] - $( - $( $stable_path:literal = $version:literal ),+ - $(, - deprecated = $deprecated_version:literal - $(, removed = $removed_version:literal )? - )? - )? - ) => { - $crate::api::VersionHistory::new( - &[ $( $unstable_path ),* ], - &[ $($( - ($crate::api::MatrixVersion::from_lit(stringify!($version)), $stable_path) - ),+)? ], - $crate::metadata!(@optional_version $($( $deprecated_version )?)?), - $crate::metadata!(@optional_version $($($( $removed_version )?)?)?), - ) - }; - - ( @optional_version ) => { None }; - ( @optional_version $version:literal ) => { Some($crate::api::MatrixVersion::from_lit(stringify!($version))) } -} diff --git a/crates/ruma-common/src/canonical_json.rs b/crates/ruma-common/src/canonical_json.rs index c337b415..2d01bd79 100644 --- a/crates/ruma-common/src/canonical_json.rs +++ b/crates/ruma-common/src/canonical_json.rs @@ -7,6 +7,7 @@ use serde_json::Value as JsonValue; mod value; +pub use self::value::{CanonicalJsonObject, CanonicalJsonValue}; use crate::RoomVersionId; #[cfg(feature = "events")] use crate::{ @@ -14,8 +15,6 @@ use crate::{ serde::Raw, }; -pub use self::value::{CanonicalJsonObject, CanonicalJsonValue}; - /// The set of possible errors when serializing to canonical JSON. #[cfg(feature = "canonical-json")] #[derive(Debug)] diff --git a/crates/ruma-common/src/events/content.rs b/crates/ruma-common/src/events/content.rs index 49bf6e7d..5ad97c5d 100644 --- a/crates/ruma-common/src/events/content.rs +++ b/crates/ruma-common/src/events/content.rs @@ -3,12 +3,11 @@ use std::fmt; use serde::{de::DeserializeOwned, Serialize}; use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue}; -use crate::serde::{CanBeEmpty, Raw}; - use super::{ EphemeralRoomEventType, GlobalAccountDataEventType, MessageLikeEventType, RoomAccountDataEventType, StateEventType, ToDeviceEventType, }; +use crate::serde::{CanBeEmpty, Raw}; /// The base trait that all event content types implement. /// diff --git a/crates/ruma-common/src/events/direct.rs b/crates/ruma-common/src/events/direct.rs index 1ab315fc..ce5575c1 100644 --- a/crates/ruma-common/src/events/direct.rs +++ b/crates/ruma-common/src/events/direct.rs @@ -59,10 +59,10 @@ impl FromIterator<(OwnedUserId, Vec)> for DirectEventContent { mod tests { use std::collections::BTreeMap; - use crate::{server_name, RoomId, UserId}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use super::{DirectEvent, DirectEventContent}; + use crate::{server_name, RoomId, UserId}; #[test] fn serialization() { diff --git a/crates/ruma-common/src/events/poll.rs b/crates/ruma-common/src/events/poll.rs index 0386ecd7..af388019 100644 --- a/crates/ruma-common/src/events/poll.rs +++ b/crates/ruma-common/src/events/poll.rs @@ -9,13 +9,12 @@ use std::collections::{BTreeMap, BTreeSet}; use indexmap::IndexMap; use js_int::uint; -use crate::{MilliSecondsSinceUnixEpoch, UserId}; - use self::{ response::OriginalSyncPollResponseEvent, start::PollContentBlock, unstable_response::OriginalSyncUnstablePollResponseEvent, unstable_start::UnstablePollStartContentBlock, }; +use crate::{MilliSecondsSinceUnixEpoch, UserId}; pub mod end; pub mod response; diff --git a/crates/ruma-common/src/events/poll/response.rs b/crates/ruma-common/src/events/poll/response.rs index 7f775ab5..e944e49c 100644 --- a/crates/ruma-common/src/events/poll/response.rs +++ b/crates/ruma-common/src/events/poll/response.rs @@ -5,9 +5,8 @@ use std::{ops::Deref, vec}; use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{events::relation::Reference, OwnedEventId}; - use super::start::PollContentBlock; +use crate::{events::relation::Reference, OwnedEventId}; /// The payload for a poll response event. /// diff --git a/crates/ruma-common/src/events/poll/start.rs b/crates/ruma-common/src/events/poll/start.rs index 24d348c7..de052d77 100644 --- a/crates/ruma-common/src/events/poll/start.rs +++ b/crates/ruma-common/src/events/poll/start.rs @@ -10,18 +10,17 @@ mod poll_answers_serde; use poll_answers_serde::PollAnswersDeHelper; -use crate::{ - events::{message::TextContentBlock, room::message::Relation}, - serde::StringEnum, - PrivOwnedStr, -}; - use super::{ compile_poll_results, end::{PollEndEventContent, PollResultsContentBlock}, generate_poll_end_fallback_text, response::OriginalSyncPollResponseEvent, }; +use crate::{ + events::{message::TextContentBlock, room::message::Relation}, + serde::StringEnum, + PrivOwnedStr, +}; /// The payload for a poll start event. /// diff --git a/crates/ruma-common/src/events/poll/unstable_response.rs b/crates/ruma-common/src/events/poll/unstable_response.rs index ce367ea6..7a2f7580 100644 --- a/crates/ruma-common/src/events/poll/unstable_response.rs +++ b/crates/ruma-common/src/events/poll/unstable_response.rs @@ -6,9 +6,8 @@ use std::ops::Deref; use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{events::relation::Reference, OwnedEventId}; - use super::unstable_start::UnstablePollStartContentBlock; +use crate::{events::relation::Reference, OwnedEventId}; /// The payload for an unstable poll response event. /// diff --git a/crates/ruma-common/src/events/poll/unstable_start.rs b/crates/ruma-common/src/events/poll/unstable_start.rs index 1366c075..e53d2359 100644 --- a/crates/ruma-common/src/events/poll/unstable_start.rs +++ b/crates/ruma-common/src/events/poll/unstable_start.rs @@ -9,8 +9,6 @@ use serde::{Deserialize, Serialize}; mod unstable_poll_answers_serde; mod unstable_poll_kind_serde; -use crate::events::room::message::Relation; - use self::unstable_poll_answers_serde::UnstablePollAnswersDeHelper; use super::{ compile_unstable_poll_results, generate_poll_end_fallback_text, @@ -18,6 +16,7 @@ use super::{ unstable_end::UnstablePollEndEventContent, unstable_response::OriginalSyncUnstablePollResponseEvent, }; +use crate::events::room::message::Relation; /// The payload for an unstable poll start event. /// diff --git a/crates/ruma-common/src/events/poll/unstable_start/unstable_poll_answers_serde.rs b/crates/ruma-common/src/events/poll/unstable_start/unstable_poll_answers_serde.rs index ee4d2360..654b330c 100644 --- a/crates/ruma-common/src/events/poll/unstable_start/unstable_poll_answers_serde.rs +++ b/crates/ruma-common/src/events/poll/unstable_start/unstable_poll_answers_serde.rs @@ -2,9 +2,8 @@ use serde::Deserialize; -use crate::events::poll::start::{PollAnswers, PollAnswersError}; - use super::{UnstablePollAnswer, UnstablePollAnswers}; +use crate::events::poll::start::{PollAnswers, PollAnswersError}; #[derive(Debug, Default, Deserialize)] pub(crate) struct UnstablePollAnswersDeHelper(Vec); diff --git a/crates/ruma-common/src/events/room.rs b/crates/ruma-common/src/events/room.rs index 1c759893..54abd5c5 100644 --- a/crates/ruma-common/src/events/room.rs +++ b/crates/ruma-common/src/events/room.rs @@ -282,9 +282,8 @@ mod tests { use serde::Deserialize; use serde_json::{from_value as from_json_value, json}; - use crate::{mxc_uri, serde::Base64}; - use super::{EncryptedFile, JsonWebKey, MediaSource}; + use crate::{mxc_uri, serde::Base64}; #[derive(Deserialize)] struct MsgWithAttachment { diff --git a/crates/ruma-common/src/events/room/message/reply.rs b/crates/ruma-common/src/events/room/message/reply.rs index a99fe743..270cf4fd 100644 --- a/crates/ruma-common/src/events/room/message/reply.rs +++ b/crates/ruma-common/src/events/room/message/reply.rs @@ -124,13 +124,12 @@ pub(crate) fn plain_and_formatted_reply_body( #[cfg(test)] mod tests { + use super::OriginalRoomMessageEvent; use crate::{ events::{room::message::RoomMessageEventContent, MessageLikeUnsigned}, owned_event_id, owned_room_id, owned_user_id, MilliSecondsSinceUnixEpoch, }; - use super::OriginalRoomMessageEvent; - #[test] fn fallback_multiline() { let (plain_quote, html_quote) = diff --git a/crates/ruma-common/src/events/room/thumbnail_source_serde.rs b/crates/ruma-common/src/events/room/thumbnail_source_serde.rs index 79b405ef..65423b3e 100644 --- a/crates/ruma-common/src/events/room/thumbnail_source_serde.rs +++ b/crates/ruma-common/src/events/room/thumbnail_source_serde.rs @@ -5,9 +5,8 @@ use serde::{ Deserialize, Deserializer, }; -use crate::OwnedMxcUri; - use super::{EncryptedFile, MediaSource}; +use crate::OwnedMxcUri; /// Serializes a MediaSource to a thumbnail source. pub(crate) fn serialize(source: &Option, serializer: S) -> Result diff --git a/crates/ruma-common/src/events/room_key.rs b/crates/ruma-common/src/events/room_key.rs index 8ab08b8d..c6b4cb5d 100644 --- a/crates/ruma-common/src/events/room_key.rs +++ b/crates/ruma-common/src/events/room_key.rs @@ -44,10 +44,10 @@ impl ToDeviceRoomKeyEventContent { #[cfg(test)] mod tests { - use crate::{owned_room_id, EventEncryptionAlgorithm}; use serde_json::{json, to_value as to_json_value}; use super::ToDeviceRoomKeyEventContent; + use crate::{owned_room_id, EventEncryptionAlgorithm}; #[test] fn serialization() { diff --git a/crates/ruma-common/src/events/secret_storage/secret.rs b/crates/ruma-common/src/events/secret_storage/secret.rs index b392822f..af7fb406 100644 --- a/crates/ruma-common/src/events/secret_storage/secret.rs +++ b/crates/ruma-common/src/events/secret_storage/secret.rs @@ -2,9 +2,10 @@ use std::collections::BTreeMap; -use crate::serde::Base64; use serde::{Deserialize, Serialize}; +use crate::serde::Base64; + /// A secret and its encrypted contents. #[derive(Clone, Debug, Serialize, Deserialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] diff --git a/crates/ruma-common/src/events/tag.rs b/crates/ruma-common/src/events/tag.rs index 745a1bde..921abe38 100644 --- a/crates/ruma-common/src/events/tag.rs +++ b/crates/ruma-common/src/events/tag.rs @@ -7,10 +7,9 @@ use std::{collections::BTreeMap, error::Error, fmt, str::FromStr}; use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::{serde::deserialize_cow_str, PrivOwnedStr}; - #[cfg(feature = "compat-tag-info")] use crate::serde::deserialize_as_optional_f64_or_string; +use crate::{serde::deserialize_cow_str, PrivOwnedStr}; /// Map of tag names to tag info. pub type Tags = BTreeMap; diff --git a/crates/ruma-common/src/identifiers.rs b/crates/ruma-common/src/identifiers.rs index d3572b3d..ec86318e 100644 --- a/crates/ruma-common/src/identifiers.rs +++ b/crates/ruma-common/src/identifiers.rs @@ -4,6 +4,11 @@ // FIXME: Remove once lint doesn't trigger on std::convert::TryFrom in identifiers/macros.rs anymore #![allow(unused_qualifications)] +#[doc(inline)] +pub use ruma_identifiers_validation::error::{ + Error as IdParseError, MatrixIdError, MatrixToError, MatrixUriError, MxcUriError, + VoipVersionIdError, +}; use serde::de::{self, Deserializer, Unexpected}; #[doc(inline)] @@ -34,11 +39,6 @@ pub use self::{ voip_id::{OwnedVoipId, VoipId}, voip_version_id::VoipVersionId, }; -#[doc(inline)] -pub use ruma_identifiers_validation::error::{ - Error as IdParseError, MatrixIdError, MatrixToError, MatrixUriError, MxcUriError, - VoipVersionIdError, -}; pub mod matrix_uri; pub mod user_id; diff --git a/crates/ruma-common/src/push/condition/flattened_json.rs b/crates/ruma-common/src/push/condition/flattened_json.rs index f4476c7b..c3e6b725 100644 --- a/crates/ruma-common/src/push/condition/flattened_json.rs +++ b/crates/ruma-common/src/push/condition/flattened_json.rs @@ -1,7 +1,8 @@ +use std::collections::BTreeMap; + use js_int::Int; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{to_value as to_json_value, value::Value as JsonValue}; -use std::collections::BTreeMap; use thiserror::Error; use tracing::{instrument, warn}; diff --git a/crates/ruma-common/src/push/condition/push_condition_serde.rs b/crates/ruma-common/src/push/condition/push_condition_serde.rs index 02526e82..cade8f72 100644 --- a/crates/ruma-common/src/push/condition/push_condition_serde.rs +++ b/crates/ruma-common/src/push/condition/push_condition_serde.rs @@ -1,11 +1,10 @@ use serde::{de, Deserialize, Serialize, Serializer}; use serde_json::value::RawValue as RawJsonValue; -use crate::serde::from_raw_json_value; - #[cfg(feature = "unstable-msc3931")] use super::RoomVersionFeature; use super::{PushCondition, RoomMemberCountIs, ScalarJsonValue}; +use crate::serde::from_raw_json_value; impl Serialize for PushCondition { fn serialize(&self, serializer: S) -> Result diff --git a/crates/ruma-common/tests/events/enums.rs b/crates/ruma-common/tests/events/enums.rs index 35eadf74..29b24b2c 100644 --- a/crates/ruma-common/tests/events/enums.rs +++ b/crates/ruma-common/tests/events/enums.rs @@ -1,25 +1,24 @@ use assert_matches2::assert_matches; use js_int::int; use ruma_common::{ - events::{MessageLikeEvent, StateEvent, SyncMessageLikeEvent, SyncStateEvent}, + events::{ + room::{ + aliases::RoomAliasesEventContent, + message::{MessageType, RoomMessageEventContent}, + power_levels::RoomPowerLevelsEventContent, + }, + AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyStateEvent, AnySyncMessageLikeEvent, + AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, EphemeralRoomEventType, + GlobalAccountDataEventType, MessageLikeEvent, MessageLikeEventType, + OriginalMessageLikeEvent, OriginalStateEvent, OriginalSyncMessageLikeEvent, + OriginalSyncStateEvent, RoomAccountDataEventType, StateEvent, StateEventType, + SyncMessageLikeEvent, SyncStateEvent, ToDeviceEventType, + }, room_alias_id, serde::test::serde_json_eq, }; use serde_json::{from_value as from_json_value, json, Value as JsonValue}; -use ruma_common::events::{ - room::{ - aliases::RoomAliasesEventContent, - message::{MessageType, RoomMessageEventContent}, - power_levels::RoomPowerLevelsEventContent, - }, - AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyStateEvent, AnySyncMessageLikeEvent, - AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, EphemeralRoomEventType, - GlobalAccountDataEventType, MessageLikeEventType, OriginalMessageLikeEvent, OriginalStateEvent, - OriginalSyncMessageLikeEvent, OriginalSyncStateEvent, RoomAccountDataEventType, StateEventType, - ToDeviceEventType, -}; - fn message_event() -> JsonValue { json!({ "content": { diff --git a/crates/ruma-common/tests/events/ephemeral_event.rs b/crates/ruma-common/tests/events/ephemeral_event.rs index a8ad01de..5cfaee52 100644 --- a/crates/ruma-common/tests/events/ephemeral_event.rs +++ b/crates/ruma-common/tests/events/ephemeral_event.rs @@ -2,17 +2,16 @@ use assert_matches2::assert_matches; use js_int::uint; use maplit::btreemap; use ruma_common::{ - event_id, events::receipt::ReceiptType, owned_event_id, owned_user_id, user_id, - MilliSecondsSinceUnixEpoch, + event_id, + events::{ + receipt::{Receipt, ReceiptEventContent, ReceiptType}, + typing::TypingEventContent, + AnyEphemeralRoomEvent, + }, + owned_event_id, owned_user_id, user_id, MilliSecondsSinceUnixEpoch, }; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; -use ruma_common::events::{ - receipt::{Receipt, ReceiptEventContent}, - typing::TypingEventContent, - AnyEphemeralRoomEvent, -}; - #[test] fn ephemeral_serialize_typing() { let content = TypingEventContent::new(vec![owned_user_id!("@carl:example.com")]); diff --git a/crates/ruma-macros/src/events/event_content.rs b/crates/ruma-macros/src/events/event_content.rs index 6162229e..b50ddb29 100644 --- a/crates/ruma-macros/src/events/event_content.rs +++ b/crates/ruma-macros/src/events/event_content.rs @@ -12,9 +12,8 @@ use syn::{ DeriveInput, Field, Ident, LitStr, Meta, Token, Type, }; -use crate::util::{m_prefix_name_to_type_name, PrivateField}; - use super::event_parse::{EventKind, EventKindVariation}; +use crate::util::{m_prefix_name_to_type_name, PrivateField}; mod kw { // This `content` field is kept when the event is redacted. diff --git a/crates/ruma-server-util/src/authorization.rs b/crates/ruma-server-util/src/authorization.rs index 5d9dba10..d7ea9db8 100644 --- a/crates/ruma-server-util/src/authorization.rs +++ b/crates/ruma-server-util/src/authorization.rs @@ -1,7 +1,6 @@ //! Common types for implementing federation authorization. use headers::{authorization::Credentials, HeaderValue}; - use ruma_common::{OwnedServerName, OwnedServerSigningKeyId}; use tracing::debug; use yap::{IntoTokens, TokenLocation, Tokens}; diff --git a/crates/ruma-signatures/src/keys.rs b/crates/ruma-signatures/src/keys.rs index 2e1e3d73..b521f495 100644 --- a/crates/ruma-signatures/src/keys.rs +++ b/crates/ruma-signatures/src/keys.rs @@ -90,9 +90,10 @@ impl Ed25519KeyPair { /// generated from the private key. This is a fallback and extra validation against /// corruption or pub fn from_der(document: &[u8], version: String) -> Result { + use pkcs8::der::Decode; + #[cfg(feature = "ring-compat")] use self::compat::CompatibleDocument; - use pkcs8::der::Decode; #[cfg(feature = "ring-compat")] let backing: Vec; diff --git a/crates/ruma-signatures/src/lib.rs b/crates/ruma-signatures/src/lib.rs index 8227e8a0..aad9e784 100644 --- a/crates/ruma-signatures/src/lib.rs +++ b/crates/ruma-signatures/src/lib.rs @@ -46,14 +46,16 @@ use ruma_common::serde::{AsRefStr, DisplayAsRefStr}; -pub use error::{Error, JsonError, ParseError, VerificationError}; -pub use functions::{ - canonical_json, content_hash, hash_and_sign_event, reference_hash, sign_json, verify_event, - verify_json, +pub use self::{ + error::{Error, JsonError, ParseError, VerificationError}, + functions::{ + canonical_json, content_hash, hash_and_sign_event, reference_hash, sign_json, verify_event, + verify_json, + }, + keys::{Ed25519KeyPair, KeyPair, PublicKeyMap, PublicKeySet}, + signatures::Signature, + verification::Verified, }; -pub use keys::{Ed25519KeyPair, KeyPair, PublicKeyMap, PublicKeySet}; -pub use signatures::Signature; -pub use verification::Verified; mod error; mod functions; diff --git a/crates/ruma-state-res/src/test_utils.rs b/crates/ruma-state-res/src/test_utils.rs index 527d6edd..a8861321 100644 --- a/crates/ruma-state-res/src/test_utils.rs +++ b/crates/ruma-state-res/src/test_utils.rs @@ -27,10 +27,9 @@ use serde_json::{ }; use tracing::info; +pub(crate) use self::event::PduEvent; use crate::{auth_types_for_event, Error, Event, EventTypeExt, Result, StateMap}; -pub(crate) use event::PduEvent; - static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0); pub(crate) fn do_check( diff --git a/crates/ruma/src/lib.rs b/crates/ruma/src/lib.rs index 79313176..1aef491e 100644 --- a/crates/ruma/src/lib.rs +++ b/crates/ruma/src/lib.rs @@ -98,17 +98,16 @@ pub use ruma_state_res as state_res; /// [apis]: https://spec.matrix.org/latest/#matrix-apis #[cfg(feature = "api")] pub mod api { - // The metadata macro is also exported at the crate root because `#[macro_export]` always - // places things at the crate root of the defining crate and we do a glob re-export of - // `ruma_common`, but here is the more logical (preferred) location. - pub use ruma_common::{api::*, metadata}; - #[cfg(any(feature = "appservice-api-c", feature = "appservice-api-s"))] #[doc(inline)] pub use ruma_appservice_api as appservice; #[cfg(any(feature = "client-api-c", feature = "client-api-s"))] #[doc(inline)] pub use ruma_client_api as client; + // The metadata macro is also exported at the crate root because `#[macro_export]` always + // places things at the crate root of the defining crate and we do a glob re-export of + // `ruma_common`, but here is the more logical (preferred) location. + pub use ruma_common::{api::*, metadata}; #[cfg(any(feature = "federation-api-c", feature = "federation-api-s"))] #[doc(inline)] pub use ruma_federation_api as federation;