From ed1f12ce377f9785ead08486d0d84da3f69be872 Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Thu, 30 Jul 2020 19:22:48 -0400 Subject: [PATCH] Run cargo fmt with merge-imports true --- matrix_sdk/examples/get_profiles.rs | 3 +- matrix_sdk/src/client.rs | 97 +++++++++++---------- matrix_sdk/src/error.rs | 8 +- matrix_sdk/src/lib.rs | 9 +- matrix_sdk/src/request_builder.rs | 11 ++- matrix_sdk_base/src/client.rs | 66 ++++++++------ matrix_sdk_base/src/event_emitter/mod.rs | 47 +++++----- matrix_sdk_base/src/lib.rs | 5 +- matrix_sdk_base/src/models/message.rs | 3 +- matrix_sdk_base/src/models/room.rs | 48 +++++----- matrix_sdk_base/src/models/room_member.rs | 6 +- matrix_sdk_base/src/state/json_store.rs | 32 +++---- matrix_sdk_base/src/state/mod.rs | 13 +-- matrix_sdk_crypto/src/device.rs | 29 +++--- matrix_sdk_crypto/src/lib.rs | 6 +- matrix_sdk_crypto/src/machine.rs | 88 +++++++++++-------- matrix_sdk_crypto/src/memory_stores.rs | 18 ++-- matrix_sdk_crypto/src/olm/account.rs | 24 ++--- matrix_sdk_crypto/src/olm/group_sessions.rs | 20 +++-- matrix_sdk_crypto/src/olm/mod.rs | 9 +- matrix_sdk_crypto/src/olm/session.rs | 14 ++- matrix_sdk_crypto/src/store/memorystore.rs | 19 ++-- matrix_sdk_crypto/src/store/mod.rs | 12 +-- matrix_sdk_crypto/src/store/sqlite.rs | 37 ++++---- matrix_sdk_test/src/lib.rs | 16 ++-- 25 files changed, 353 insertions(+), 287 deletions(-) diff --git a/matrix_sdk/examples/get_profiles.rs b/matrix_sdk/examples/get_profiles.rs index b9ad61dc..6850c404 100644 --- a/matrix_sdk/examples/get_profiles.rs +++ b/matrix_sdk/examples/get_profiles.rs @@ -1,5 +1,4 @@ -use std::convert::TryFrom; -use std::{env, process::exit}; +use std::{convert::TryFrom, env, process::exit}; use url::Url; diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 4fc63f81..87303b3f 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -15,19 +15,23 @@ #[cfg(feature = "encryption")] use std::collections::BTreeMap; -use std::collections::HashMap; -use std::convert::{TryFrom, TryInto}; -use std::fmt::{self, Debug}; -use std::path::Path; -use std::result::Result as StdResult; -use std::sync::Arc; +use std::{ + collections::HashMap, + convert::{TryFrom, TryInto}, + fmt::{self, Debug}, + path::Path, + result::Result as StdResult, + sync::Arc, +}; -use matrix_sdk_common::identifiers::ServerName; -use matrix_sdk_common::instant::{Duration, Instant}; -use matrix_sdk_common::js_int::UInt; -use matrix_sdk_common::locks::RwLock; -use matrix_sdk_common::presence::PresenceState; -use matrix_sdk_common::uuid::Uuid; +use matrix_sdk_common::{ + identifiers::ServerName, + instant::{Duration, Instant}, + js_int::UInt, + locks::RwLock, + presence::PresenceState, + uuid::Uuid, +}; use futures_timer::Delay as sleep; use std::future::Future; @@ -35,23 +39,22 @@ use std::future::Future; use tracing::{debug, warn}; use tracing::{error, info, instrument, trace}; -use http::Method as HttpMethod; -use http::Response as HttpResponse; +use http::{Method as HttpMethod, Response as HttpResponse}; use reqwest::header::{HeaderValue, InvalidHeaderValue, AUTHORIZATION}; use url::Url; -use crate::events::room::message::MessageEventContent; -use crate::events::EventType; -use crate::identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}; -use crate::Endpoint; +use crate::{ + events::{room::message::MessageEventContent, EventType}, + identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}, + Endpoint, +}; #[cfg(feature = "encryption")] use crate::identifiers::DeviceId; -use crate::api; #[cfg(not(target_arch = "wasm32"))] use crate::VERSION; -use crate::{Error, EventEmitter, Result}; +use crate::{api, Error, EventEmitter, Result}; use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore}; const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); @@ -269,27 +272,27 @@ impl SyncSettings { } } -use api::r0::account::register; -use api::r0::directory::get_public_rooms; -use api::r0::directory::get_public_rooms_filtered; #[cfg(feature = "encryption")] use api::r0::keys::{claim_keys, get_keys, upload_keys, KeyAlgorithm}; -use api::r0::membership::{ - ban_user, forget_room, - invite_user::{self, InvitationRecipient}, - join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid, -}; -use api::r0::message::create_message_event; -use api::r0::message::get_message_events; -use api::r0::read_marker::set_read_marker; -use api::r0::receipt::create_receipt; -use api::r0::room::create_room; -use api::r0::session::login; -use api::r0::sync::sync_events; #[cfg(feature = "encryption")] use api::r0::to_device::send_event_to_device; -use api::r0::typing::create_typing_event; -use api::r0::uiaa::UiaaResponse; +use api::r0::{ + account::register, + directory::{get_public_rooms, get_public_rooms_filtered}, + membership::{ + ban_user, forget_room, + invite_user::{self, InvitationRecipient}, + join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid, + }, + message::{create_message_event, get_message_events}, + read_marker::set_read_marker, + receipt::create_receipt, + room::create_room, + session::login, + sync::sync_events, + typing::create_typing_event, + uiaa::UiaaResponse, +}; impl Client { /// Creates a new client for making HTTP requests to the given homeserver. @@ -1538,23 +1541,27 @@ mod test { get_public_rooms_filtered::{self, Filter}, invite_user, kick_user, leave_room, register::RegistrationKind, - set_read_marker, Invite3pid, MessageEventContent, + set_read_marker, Client, ClientConfig, Invite3pid, MessageEventContent, Session, + SyncSettings, Url, }; - use super::{Client, ClientConfig, Session, SyncSettings, Url}; use crate::events::room::message::TextMessageEventContent; - use crate::identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}; - use crate::{RegistrationBuilder, RoomListFilterBuilder}; + use crate::{ + identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}, + RegistrationBuilder, RoomListFilterBuilder, + }; use matrix_sdk_base::JsonStore; use matrix_sdk_test::{test_json, EventBuilder, EventsJson}; use mockito::{mock, Matcher}; use tempfile::tempdir; - use std::convert::{TryFrom, TryInto}; - use std::path::Path; - use std::str::FromStr; - use std::time::Duration; + use std::{ + convert::{TryFrom, TryInto}, + path::Path, + str::FromStr, + time::Duration, + }; #[tokio::test] async fn test_join_leave_room() { diff --git a/matrix_sdk/src/error.rs b/matrix_sdk/src/error.rs index c293797a..e26fcf80 100644 --- a/matrix_sdk/src/error.rs +++ b/matrix_sdk/src/error.rs @@ -20,10 +20,10 @@ use thiserror::Error; use matrix_sdk_base::Error as MatrixError; -use crate::api::r0::uiaa::UiaaResponse as UiaaError; -use crate::api::Error as RumaClientError; -use crate::FromHttpResponseError as RumaResponseError; -use crate::IntoHttpError as RumaIntoHttpError; +use crate::{ + api::{r0::uiaa::UiaaResponse as UiaaError, Error as RumaClientError}, + FromHttpResponseError as RumaResponseError, IntoHttpError as RumaIntoHttpError, +}; /// Result type of the rust-sdk. pub type Result = std::result::Result; diff --git a/matrix_sdk/src/lib.rs b/matrix_sdk/src/lib.rs index 9b72cd43..f3e0e4ad 100644 --- a/matrix_sdk/src/lib.rs +++ b/matrix_sdk/src/lib.rs @@ -36,13 +36,14 @@ unused_qualifications )] -pub use matrix_sdk_base::Error as BaseError; #[cfg(not(target_arch = "wasm32"))] pub use matrix_sdk_base::JsonStore; -pub use matrix_sdk_base::{CustomOrRawEvent, EventEmitter, Room, Session, SyncRoom}; +pub use matrix_sdk_base::{ + CustomOrRawEvent, Error as BaseError, EventEmitter, Room, RoomState, Session, StateStore, + SyncRoom, +}; #[cfg(feature = "messages")] -pub use matrix_sdk_base::{MessageQueue, PossiblyRedactedExt}; -pub use matrix_sdk_base::{RoomState, StateStore}; +pub use matrix_sdk_base::{MessageQueue, MessageWrapper, PossiblyRedactedExt}; pub use matrix_sdk_common::*; pub use reqwest::header::InvalidHeaderValue; diff --git a/matrix_sdk/src/request_builder.rs b/matrix_sdk/src/request_builder.rs index 88ba1d5f..6591a7bb 100644 --- a/matrix_sdk/src/request_builder.rs +++ b/matrix_sdk/src/request_builder.rs @@ -454,10 +454,13 @@ mod test { use std::collections::BTreeMap; use super::*; - use crate::api::r0::filter::{LazyLoadOptions, RoomEventFilter}; - use crate::events::room::power_levels::NotificationPowerLevels; - use crate::js_int::Int; - use crate::{identifiers::RoomId, Client, Session}; + use crate::{ + api::r0::filter::{LazyLoadOptions, RoomEventFilter}, + events::room::power_levels::NotificationPowerLevels, + identifiers::RoomId, + js_int::Int, + Client, Session, + }; use matrix_sdk_test::test_json; use mockito::{mock, Matcher}; diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index 1f2bc2a2..99f60be9 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -13,35 +13,40 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; #[cfg(feature = "encryption")] use std::collections::{BTreeMap, HashSet}; -use std::fmt; -use std::path::{Path, PathBuf}; -use std::sync::Arc; +use std::{ + collections::HashMap, + fmt, + path::{Path, PathBuf}, + sync::Arc, +}; use zeroize::Zeroizing; use std::result::Result as StdResult; -use crate::api::r0 as api; -use crate::error::Result; -use crate::events::presence::PresenceEvent; +use crate::{api::r0 as api, error::Result, events::presence::PresenceEvent}; // `NonRoomEvent` is what it is aliased as -use crate::event_emitter::CustomOrRawEvent; -use crate::events::ignored_user_list::IgnoredUserListEvent; -use crate::events::push_rules::PushRulesEvent; -use crate::events::room::member::MemberEventContent; -use crate::identifiers::{RoomId, UserId}; -use crate::models::Room; -use crate::push::Ruleset; -use crate::session::Session; -use crate::state::{AllRooms, ClientState, StateStore}; -use crate::EventEmitter; -use matrix_sdk_common::events::{ - AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, - AnySyncRoomEvent, AnySyncStateEvent, +use crate::{ + event_emitter::CustomOrRawEvent, + events::{ + ignored_user_list::IgnoredUserListEvent, push_rules::PushRulesEvent, + room::member::MemberEventContent, + }, + identifiers::{RoomId, UserId}, + models::Room, + push::Ruleset, + session::Session, + state::{AllRooms, ClientState, StateStore}, + EventEmitter, +}; +use matrix_sdk_common::{ + events::{ + AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, + AnySyncRoomEvent, AnySyncStateEvent, + }, + Raw, }; -use matrix_sdk_common::Raw; #[cfg(feature = "encryption")] use matrix_sdk_common::locks::Mutex; @@ -1831,10 +1836,12 @@ impl BaseClient { #[cfg(test)] mod test { - use crate::identifiers::{RoomId, UserId}; #[cfg(feature = "messages")] use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw}; - use crate::{BaseClient, Session}; + use crate::{ + identifiers::{RoomId, UserId}, + BaseClient, Session, + }; use matrix_sdk_common_macros::async_trait; use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson}; use serde_json::json; @@ -1997,11 +2004,13 @@ mod test { use super::*; use crate::{EventEmitter, SyncRoom}; - use matrix_sdk_common::events::{ - room::member::{MemberEventContent, MembershipChange}, - SyncStateEvent, + use matrix_sdk_common::{ + events::{ + room::member::{MemberEventContent, MembershipChange}, + SyncStateEvent, + }, + locks::RwLock, }; - use matrix_sdk_common::locks::RwLock; use std::sync::{ atomic::{AtomicBool, Ordering}, Arc, @@ -2253,8 +2262,7 @@ mod test { use super::*; use crate::{EventEmitter, SyncRoom}; - use matrix_sdk_common::api::r0::sync::sync_events; - use matrix_sdk_common::locks::RwLock; + use matrix_sdk_common::{api::r0::sync::sync_events, locks::RwLock}; use std::sync::{ atomic::{AtomicBool, Ordering}, Arc, diff --git a/matrix_sdk_base/src/event_emitter/mod.rs b/matrix_sdk_base/src/event_emitter/mod.rs index 150cc74f..faa416bf 100644 --- a/matrix_sdk_base/src/event_emitter/mod.rs +++ b/matrix_sdk_base/src/event_emitter/mod.rs @@ -17,29 +17,31 @@ use std::sync::Arc; use matrix_sdk_common::locks::RwLock; use serde_json::value::RawValue as RawJsonValue; -use crate::events::{ - custom::CustomEventContent, - fully_read::FullyReadEventContent, - ignored_user_list::IgnoredUserListEventContent, - presence::PresenceEvent, - push_rules::PushRulesEventContent, - receipt::ReceiptEventContent, - room::{ - aliases::AliasesEventContent, - avatar::AvatarEventContent, - canonical_alias::CanonicalAliasEventContent, - join_rules::JoinRulesEventContent, - member::MemberEventContent, - message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent}, - name::NameEventContent, - power_levels::PowerLevelsEventContent, - redaction::SyncRedactionEvent, - tombstone::TombstoneEventContent, +use crate::{ + events::{ + custom::CustomEventContent, + fully_read::FullyReadEventContent, + ignored_user_list::IgnoredUserListEventContent, + presence::PresenceEvent, + push_rules::PushRulesEventContent, + receipt::ReceiptEventContent, + room::{ + aliases::AliasesEventContent, + avatar::AvatarEventContent, + canonical_alias::CanonicalAliasEventContent, + join_rules::JoinRulesEventContent, + member::MemberEventContent, + message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent}, + name::NameEventContent, + power_levels::PowerLevelsEventContent, + redaction::SyncRedactionEvent, + tombstone::TombstoneEventContent, + }, + typing::TypingEventContent, + BasicEvent, StrippedStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent, }, - typing::TypingEventContent, - BasicEvent, StrippedStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent, + Room, RoomState, }; -use crate::{Room, RoomState}; use matrix_sdk_common_macros::async_trait; /// Type alias for `RoomState` enum when passed to `EventEmitter` methods. @@ -471,8 +473,7 @@ mod test { } } - use crate::identifiers::UserId; - use crate::{BaseClient, Session}; + use crate::{identifiers::UserId, BaseClient, Session}; use std::convert::TryFrom; diff --git a/matrix_sdk_base/src/lib.rs b/matrix_sdk_base/src/lib.rs index f7e07bd2..9d32fa56 100644 --- a/matrix_sdk_base/src/lib.rs +++ b/matrix_sdk_base/src/lib.rs @@ -35,7 +35,10 @@ unused_qualifications )] -pub use crate::{error::Error, error::Result, session::Session}; +pub use crate::{ + error::{Error, Result}, + session::Session, +}; pub use matrix_sdk_common::*; mod client; diff --git a/matrix_sdk_base/src/models/message.rs b/matrix_sdk_base/src/models/message.rs index 5b496766..29b9a582 100644 --- a/matrix_sdk_base/src/models/message.rs +++ b/matrix_sdk_base/src/models/message.rs @@ -160,8 +160,7 @@ pub(crate) mod ser_deser { #[cfg(test)] mod test { - use std::collections::HashMap; - use std::convert::TryFrom; + use std::{collections::HashMap, convert::TryFrom}; use matrix_sdk_common::{ events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent}, diff --git a/matrix_sdk_base/src/models/room.rs b/matrix_sdk_base/src/models/room.rs index 8d9fb2d9..6802f1e9 100644 --- a/matrix_sdk_base/src/models/room.rs +++ b/matrix_sdk_base/src/models/room.rs @@ -13,10 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::{BTreeMap, HashMap, HashSet}; -use std::convert::TryFrom; #[cfg(feature = "messages")] use std::ops::DerefMut; +use std::{ + collections::{BTreeMap, HashMap, HashSet}, + convert::TryFrom, +}; use serde::{Deserialize, Serialize}; use tracing::{debug, error, trace}; @@ -24,20 +26,22 @@ use tracing::{debug, error, trace}; #[cfg(feature = "messages")] use super::message::MessageQueue; use super::RoomMember; -use crate::api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount}; -use crate::events::{ - presence::{PresenceEvent, PresenceEventContent}, - room::{ - aliases::AliasesEventContent, - canonical_alias::CanonicalAliasEventContent, - encryption::EncryptionEventContent, - member::{MemberEventContent, MembershipChange, MembershipState}, - name::NameEventContent, - power_levels::{NotificationPowerLevels, PowerLevelsEventContent}, - tombstone::TombstoneEventContent, +use crate::{ + api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount}, + events::{ + presence::{PresenceEvent, PresenceEventContent}, + room::{ + aliases::AliasesEventContent, + canonical_alias::CanonicalAliasEventContent, + encryption::EncryptionEventContent, + member::{MemberEventContent, MembershipChange, MembershipState}, + name::NameEventContent, + power_levels::{NotificationPowerLevels, PowerLevelsEventContent}, + tombstone::TombstoneEventContent, + }, + Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, + StrippedStateEvent, SyncStateEvent, }, - Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, - StrippedStateEvent, SyncStateEvent, }; #[cfg(feature = "messages")] @@ -670,8 +674,7 @@ impl Room { #[cfg(feature = "messages")] #[cfg_attr(docsrs, doc(cfg(feature = "messages")))] pub fn handle_redaction(&mut self, redacted_event: &SyncRedactionEvent) -> bool { - use crate::identifiers::RoomVersionId; - use crate::models::message::PossiblyRedactedExt; + use crate::{identifiers::RoomVersionId, models::message::PossiblyRedactedExt}; if let Some(mut msg) = self .messages @@ -1080,9 +1083,11 @@ impl Describe for MembershipChange { #[cfg(test)] mod test { use super::*; - use crate::events::{room::encryption::EncryptionEventContent, Unsigned}; - use crate::identifiers::{EventId, UserId}; - use crate::{BaseClient, Raw, Session}; + use crate::{ + events::{room::encryption::EncryptionEventContent, Unsigned}, + identifiers::{EventId, UserId}, + BaseClient, Raw, Session, + }; use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile}; use std::time::SystemTime; @@ -1090,8 +1095,7 @@ mod test { #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; - use std::convert::TryFrom; - use std::ops::Deref; + use std::{convert::TryFrom, ops::Deref}; async fn get_client() -> BaseClient { let session = Session { diff --git a/matrix_sdk_base/src/models/room_member.rs b/matrix_sdk_base/src/models/room_member.rs index 9baf8482..79bb0c8d 100644 --- a/matrix_sdk_base/src/models/room_member.rs +++ b/matrix_sdk_base/src/models/room_member.rs @@ -154,8 +154,10 @@ impl RoomMember { mod test { use matrix_sdk_test::{async_test, EventBuilder, EventsJson}; - use crate::identifiers::{RoomId, UserId}; - use crate::{BaseClient, Session}; + use crate::{ + identifiers::{RoomId, UserId}, + BaseClient, Session, + }; use crate::js_int::int; diff --git a/matrix_sdk_base/src/state/json_store.rs b/matrix_sdk_base/src/state/json_store.rs index c7ef514f..204eb67a 100644 --- a/matrix_sdk_base/src/state/json_store.rs +++ b/matrix_sdk_base/src/state/json_store.rs @@ -1,16 +1,15 @@ -use std::collections::HashMap; -use std::fmt; -use std::fs; -use std::path::{Path, PathBuf}; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, +use std::{ + collections::HashMap, + fmt, fs, + path::{Path, PathBuf}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, }; -use matrix_sdk_common::identifiers::RoomId; -use matrix_sdk_common::locks::RwLock; -use tokio::fs as async_fs; -use tokio::io::AsyncWriteExt; +use matrix_sdk_common::{identifiers::RoomId, locks::RwLock}; +use tokio::{fs as async_fs, io::AsyncWriteExt}; use super::{AllRooms, ClientState, StateStore}; use crate::{Error, Result, Room, RoomState, Session}; @@ -218,14 +217,15 @@ impl StateStore for JsonStore { mod test { use super::*; - use std::convert::TryFrom; - use std::path::PathBuf; + use std::{convert::TryFrom, path::PathBuf}; use tempfile::tempdir; - use crate::identifiers::{RoomId, UserId}; - use crate::push::Ruleset; - use crate::{BaseClient, BaseClientConfig, Session}; + use crate::{ + identifiers::{RoomId, UserId}, + push::Ruleset, + BaseClient, BaseClientConfig, Session, + }; use matrix_sdk_test::{sync_response, SyncResponseFile}; diff --git a/matrix_sdk_base/src/state/mod.rs b/matrix_sdk_base/src/state/mod.rs index 3b5d0203..6e7ac5a2 100644 --- a/matrix_sdk_base/src/state/mod.rs +++ b/matrix_sdk_base/src/state/mod.rs @@ -22,10 +22,12 @@ mod json_store; #[cfg(not(target_arch = "wasm32"))] pub use json_store::JsonStore; -use crate::client::{BaseClient, Token}; -use crate::identifiers::{RoomId, UserId}; -use crate::push::Ruleset; -use crate::{Result, Room, RoomState, Session}; +use crate::{ + client::{BaseClient, Token}, + identifiers::{RoomId, UserId}, + push::Ruleset, + Result, Room, RoomState, Session, +}; #[cfg(not(target_arch = "wasm32"))] use matrix_sdk_common_macros::send_sync; @@ -117,8 +119,7 @@ pub trait StateStore { mod test { use super::*; - use std::collections::HashMap; - use std::convert::TryFrom; + use std::{collections::HashMap, convert::TryFrom}; use crate::identifiers::RoomId; diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/device.rs index fc01f73c..fe59f1d4 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/device.rs @@ -12,22 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::BTreeMap; -use std::convert::TryFrom; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; +use std::{ + collections::BTreeMap, + convert::TryFrom, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, +}; use atomic::Atomic; use serde_json::{json, Value}; #[cfg(test)] use super::OlmMachine; -use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, SignedKey}; -use matrix_sdk_common::events::Algorithm; -use matrix_sdk_common::identifiers::{DeviceId, UserId}; +use matrix_sdk_common::{ + api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, SignedKey}, + events::Algorithm, + identifiers::{DeviceId, UserId}, +}; -use crate::error::SignatureError; -use crate::verify_json; +use crate::{error::SignatureError, verify_json}; /// A device represents a E2EE capable client of an user. #[derive(Debug, Clone)] @@ -230,8 +235,10 @@ pub(crate) mod test { use std::convert::TryFrom; use crate::device::{Device, TrustState}; - use matrix_sdk_common::api::r0::keys::{DeviceKeys, KeyAlgorithm}; - use matrix_sdk_common::identifiers::UserId; + use matrix_sdk_common::{ + api::r0::keys::{DeviceKeys, KeyAlgorithm}, + identifiers::UserId, + }; fn device_keys() -> DeviceKeys { let device_keys = json!({ diff --git a/matrix_sdk_crypto/src/lib.rs b/matrix_sdk_crypto/src/lib.rs index 332e61db..6abb7a9f 100644 --- a/matrix_sdk_crypto/src/lib.rs +++ b/matrix_sdk_crypto/src/lib.rs @@ -43,8 +43,10 @@ pub use store::sqlite::SqliteStore; pub use store::{CryptoStore, CryptoStoreError}; use error::SignatureError; -use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}; -use matrix_sdk_common::identifiers::UserId; +use matrix_sdk_common::{ + api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}, + identifiers::UserId, +}; use olm_rs::utility::OlmUtility; use serde_json::Value; diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index b569e429..67ba2f21 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -12,35 +12,44 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::{BTreeMap, HashMap, HashSet}; -use std::convert::TryFrom; -use std::convert::TryInto; -use std::mem; #[cfg(feature = "sqlite-cryptostore")] use std::path::Path; -use std::result::Result as StdResult; - -use super::error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}; -use super::olm::{ - Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage, OutboundGroupSession, +use std::{ + collections::{BTreeMap, HashMap, HashSet}, + convert::{TryFrom, TryInto}, + mem, + result::Result as StdResult, }; -use super::store::memorystore::MemoryStore; + #[cfg(feature = "sqlite-cryptostore")] use super::store::sqlite::SqliteStore; -use super::{device::Device, store::Result as StoreResult, CryptoStore}; - -use matrix_sdk_common::events::{ - forwarded_room_key::ForwardedRoomKeyEventContent, room::encrypted::EncryptedEventContent, - room::message::MessageEventContent, room_key::RoomKeyEventContent, - room_key_request::RoomKeyRequestEventContent, Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, - EventType, SyncMessageEvent, ToDeviceEvent, +use super::{ + device::Device, + error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}, + olm::{ + Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage, + OutboundGroupSession, + }, + store::{memorystore::MemoryStore, Result as StoreResult}, + CryptoStore, +}; + +use matrix_sdk_common::{ + api, + events::{ + forwarded_room_key::ForwardedRoomKeyEventContent, + room::{encrypted::EncryptedEventContent, message::MessageEventContent}, + room_key::RoomKeyEventContent, + room_key_request::RoomKeyRequestEventContent, + Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, ToDeviceEvent, + }, + identifiers::{DeviceId, RoomId, UserId}, + uuid::Uuid, + Raw, }; -use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; -use matrix_sdk_common::uuid::Uuid; -use matrix_sdk_common::{api, Raw}; -use api::r0::keys; use api::r0::{ + keys, keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey}, sync::sync_events::Response as SyncResponse, to_device::{send_event_to_device::Request as ToDeviceRequest, DeviceIdOrAllDevices}, @@ -1166,30 +1175,33 @@ mod test { static USER_ID: &str = "@bob:example.org"; use matrix_sdk_common::js_int::uint; - use std::collections::BTreeMap; - use std::convert::TryFrom; - use std::convert::TryInto; - use std::time::SystemTime; + use std::{ + collections::BTreeMap, + convert::{TryFrom, TryInto}, + time::SystemTime, + }; use http::Response; use serde_json::json; - use crate::machine::{OlmMachine, OneTimeKeys}; - use crate::{verify_json, Device}; + use crate::{ + machine::{OlmMachine, OneTimeKeys}, + verify_json, Device, + }; - use matrix_sdk_common::api::r0::{ - keys, to_device::send_event_to_device::Request as ToDeviceRequest, - }; - use matrix_sdk_common::events::{ - room::{ - encrypted::EncryptedEventContent, - message::{MessageEventContent, TextMessageEventContent}, + use matrix_sdk_common::{ + api::r0::{keys, to_device::send_event_to_device::Request as ToDeviceRequest}, + events::{ + room::{ + encrypted::EncryptedEventContent, + message::{MessageEventContent, TextMessageEventContent}, + }, + AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, + ToDeviceEvent, Unsigned, }, - AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, - ToDeviceEvent, Unsigned, + identifiers::{DeviceId, EventId, RoomId, UserId}, + Raw, }; - use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId}; - use matrix_sdk_common::Raw; use matrix_sdk_test::test_json; fn alice_id() -> UserId { diff --git a/matrix_sdk_crypto/src/memory_stores.rs b/matrix_sdk_crypto/src/memory_stores.rs index 72d91395..0b465c4a 100644 --- a/matrix_sdk_crypto/src/memory_stores.rs +++ b/matrix_sdk_crypto/src/memory_stores.rs @@ -12,14 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; use dashmap::{DashMap, ReadOnlyView}; use matrix_sdk_common::locks::Mutex; -use super::device::Device; -use super::olm::{InboundGroupSession, Session}; +use super::{ + device::Device, + olm::{InboundGroupSession, Session}, +}; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; /// In-memory store for Olm Sessions. @@ -211,10 +212,11 @@ impl DeviceStore { mod test { use std::convert::TryFrom; - use crate::device::test::get_device; - use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore}; - use crate::olm::test::get_account_and_session; - use crate::olm::InboundGroupSession; + use crate::{ + device::test::get_device, + memory_stores::{DeviceStore, GroupSessionStore, SessionStore}, + olm::{test::get_account_and_session, InboundGroupSession}, + }; use matrix_sdk_common::identifiers::RoomId; #[tokio::test] diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index a1308666..9fa2c17f 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -13,23 +13,27 @@ // limitations under the License. use matrix_sdk_common::instant::Instant; -use std::convert::TryFrom; -use std::convert::TryInto; -use std::fmt; -use std::sync::atomic::{AtomicBool, AtomicI64, Ordering}; -use std::sync::Arc; +use std::{ + convert::{TryFrom, TryInto}, + fmt, + sync::{ + atomic::{AtomicBool, AtomicI64, Ordering}, + Arc, + }, +}; use matrix_sdk_common::locks::Mutex; use serde_json::{json, Value}; use std::collections::BTreeMap; pub use olm_rs::account::IdentityKeys; -use olm_rs::account::{OlmAccount, OneTimeKeys}; -use olm_rs::errors::{OlmAccountError, OlmSessionError}; -use olm_rs::PicklingMode; +use olm_rs::{ + account::{OlmAccount, OneTimeKeys}, + errors::{OlmAccountError, OlmSessionError}, + PicklingMode, +}; -use crate::device::Device; -use crate::error::SessionCreationError; +use crate::{device::Device, error::SessionCreationError}; pub use olm_rs::{ session::{OlmMessage, PreKeyMessage}, utility::OlmUtility, diff --git a/matrix_sdk_crypto/src/olm/group_sessions.rs b/matrix_sdk_crypto/src/olm/group_sessions.rs index 10c61904..e3725d04 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions.rs @@ -13,10 +13,14 @@ // limitations under the License. use matrix_sdk_common::instant::Instant; -use std::convert::TryInto; -use std::fmt; -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use std::sync::Arc; +use std::{ + convert::TryInto, + fmt, + sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, + }, +}; use matrix_sdk_common::locks::Mutex; use serde::Serialize; @@ -24,10 +28,10 @@ use serde_json::{json, Value}; use zeroize::Zeroize; pub use olm_rs::account::IdentityKeys; -use olm_rs::errors::OlmGroupSessionError; -use olm_rs::inbound_group_session::OlmInboundGroupSession; -use olm_rs::outbound_group_session::OlmOutboundGroupSession; -use olm_rs::PicklingMode; +use olm_rs::{ + errors::OlmGroupSessionError, inbound_group_session::OlmInboundGroupSession, + outbound_group_session::OlmOutboundGroupSession, PicklingMode, +}; use crate::error::{EventError, MegolmResult}; pub use olm_rs::{ diff --git a/matrix_sdk_crypto/src/olm/mod.rs b/matrix_sdk_crypto/src/olm/mod.rs index e6e31c3f..18f21936 100644 --- a/matrix_sdk_crypto/src/olm/mod.rs +++ b/matrix_sdk_crypto/src/olm/mod.rs @@ -23,11 +23,12 @@ pub use session::{OlmMessage, Session}; #[cfg(test)] pub(crate) mod test { use crate::olm::{Account, InboundGroupSession, Session}; - use matrix_sdk_common::api::r0::keys::SignedKey; - use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; + use matrix_sdk_common::{ + api::r0::keys::SignedKey, + identifiers::{DeviceId, RoomId, UserId}, + }; use olm_rs::session::OlmMessage; - use std::collections::BTreeMap; - use std::convert::TryFrom; + use std::{collections::BTreeMap, convert::TryFrom}; fn alice_id() -> UserId { UserId::try_from("@alice:example.org").unwrap() diff --git a/matrix_sdk_crypto/src/olm/session.rs b/matrix_sdk_crypto/src/olm/session.rs index d6b11de8..eb52cebc 100644 --- a/matrix_sdk_crypto/src/olm/session.rs +++ b/matrix_sdk_crypto/src/olm/session.rs @@ -12,13 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::BTreeMap; -use std::fmt; -use std::sync::Arc; +use std::{collections::BTreeMap, fmt, sync::Arc}; -use olm_rs::errors::OlmSessionError; -use olm_rs::session::OlmSession; -use olm_rs::PicklingMode; +use olm_rs::{errors::OlmSessionError, session::OlmSession, PicklingMode}; use serde_json::{json, Value}; @@ -28,8 +24,10 @@ pub use olm_rs::{ }; use super::IdentityKeys; -use crate::error::{EventError, OlmResult}; -use crate::Device; +use crate::{ + error::{EventError, OlmResult}, + Device, +}; use matrix_sdk_common::{ api::r0::keys::KeyAlgorithm, diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index a911320f..071c697a 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashSet; -use std::sync::Arc; +use std::{collections::HashSet, sync::Arc}; use async_trait::async_trait; use matrix_sdk_common::locks::Mutex; use super::{Account, CryptoStore, InboundGroupSession, Result, Session}; -use crate::device::Device; -use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}; +use crate::{ + device::Device, + memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}, +}; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; #[derive(Debug)] @@ -126,11 +127,11 @@ impl CryptoStore for MemoryStore { mod test { use std::convert::TryFrom; - use crate::device::test::get_device; - use crate::olm::test::get_account_and_session; - use crate::olm::InboundGroupSession; - use crate::store::memorystore::MemoryStore; - use crate::store::CryptoStore; + use crate::{ + device::test::get_device, + olm::{test::get_account_and_session, InboundGroupSession}, + store::{memorystore::MemoryStore, CryptoStore}, + }; use matrix_sdk_common::identifiers::RoomId; #[tokio::test] diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 2e40503e..ab0f2a24 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -13,9 +13,7 @@ // limitations under the License. use core::fmt::Debug; -use std::collections::HashSet; -use std::io::Error as IoError; -use std::sync::Arc; +use std::{collections::HashSet, io::Error as IoError, sync::Arc}; use url::ParseError; use async_trait::async_trait; @@ -23,9 +21,11 @@ use matrix_sdk_common::locks::Mutex; use serde_json::Error as SerdeError; use thiserror::Error; -use super::device::Device; -use super::memory_stores::UserDevices; -use super::olm::{Account, InboundGroupSession, Session}; +use super::{ + device::Device, + memory_stores::UserDevices, + olm::{Account, InboundGroupSession, Session}, +}; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; use matrix_sdk_common_macros::send_sync; use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError}; diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 786863a8..6f407be4 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -13,11 +13,13 @@ // limitations under the License. use matrix_sdk_common::instant::{Duration, Instant}; -use std::collections::{BTreeMap, HashSet}; -use std::convert::TryFrom; -use std::path::{Path, PathBuf}; -use std::result::Result as StdResult; -use std::sync::Arc; +use std::{ + collections::{BTreeMap, HashSet}, + convert::TryFrom, + path::{Path, PathBuf}, + result::Result as StdResult, + sync::Arc, +}; use url::Url; use async_trait::async_trait; @@ -27,12 +29,16 @@ use sqlx::{query, query_as, sqlite::SqliteQueryAs, Connect, Executor, SqliteConn use zeroize::Zeroizing; use super::{CryptoStore, CryptoStoreError, Result}; -use crate::device::{Device, TrustState}; -use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}; -use crate::{Account, IdentityKeys, InboundGroupSession, Session}; -use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}; -use matrix_sdk_common::events::Algorithm; -use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; +use crate::{ + device::{Device, TrustState}, + memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}, + Account, IdentityKeys, InboundGroupSession, Session, +}; +use matrix_sdk_common::{ + api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}, + events::Algorithm, + identifiers::{DeviceId, RoomId, UserId}, +}; /// SQLite based implementation of a `CryptoStore`. pub struct SqliteStore { @@ -887,10 +893,11 @@ impl std::fmt::Debug for SqliteStore { #[cfg(test)] mod test { - use crate::device::test::get_device; - use crate::olm::GroupSessionKey; - use matrix_sdk_common::api::r0::keys::SignedKey; - use matrix_sdk_common::identifiers::{DeviceId, UserId}; + use crate::{device::test::get_device, olm::GroupSessionKey}; + use matrix_sdk_common::{ + api::r0::keys::SignedKey, + identifiers::{DeviceId, UserId}, + }; use olm_rs::outbound_group_session::OlmOutboundGroupSession; use std::collections::BTreeMap; use tempfile::tempdir; diff --git a/matrix_sdk_test/src/lib.rs b/matrix_sdk_test/src/lib.rs index 2a33ce3a..c3a149b1 100644 --- a/matrix_sdk_test/src/lib.rs +++ b/matrix_sdk_test/src/lib.rs @@ -1,15 +1,15 @@ -use std::collections::HashMap; -use std::convert::TryFrom; -use std::panic; +use std::{collections::HashMap, convert::TryFrom, panic}; use http::Response; -use matrix_sdk_common::api::r0::sync::sync_events::Response as SyncResponse; -use matrix_sdk_common::events::{ - presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, - AnySyncStateEvent, +use matrix_sdk_common::{ + api::r0::sync::sync_events::Response as SyncResponse, + events::{ + presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, + AnySyncStateEvent, + }, + identifiers::RoomId, }; -use matrix_sdk_common::identifiers::RoomId; use serde_json::Value as JsonValue; pub use matrix_sdk_test_macros::async_test;