From 5f09d091cbc1100beec22fa879de76dc2b8f6300 Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Wed, 12 May 2021 13:20:52 -0400 Subject: [PATCH] Add cargo fmt to ci using nightly --- .github/workflows/ci.yml | 2 +- rustfmt.toml => .rustfmt.toml | 0 matrix_sdk/examples/command_bot.rs | 13 ++++---- matrix_sdk/src/device.rs | 3 +- matrix_sdk/src/event_handler/mod.rs | 13 ++------ matrix_sdk/src/http_client.rs | 9 +++-- matrix_sdk/src/lib.rs | 27 ++++++++------- matrix_sdk/src/room/common.rs | 33 ++++++++++--------- matrix_sdk/src/room/invited.rs | 8 +++-- matrix_sdk/src/room/left.rs | 8 +++-- matrix_sdk_appservice/src/lib.rs | 30 ++++++++++------- matrix_sdk_appservice/tests/actix.rs | 4 +-- .../src/store/sled_store/store_key.rs | 6 ++-- matrix_sdk_crypto/benches/perf.rs | 15 +++++---- matrix_sdk_crypto/src/identities/mod.rs | 8 ++--- .../src/olm/group_sessions/inbound.rs | 3 +- matrix_sdk_crypto/src/olm/session.rs | 8 +++-- matrix_sdk_crypto/src/olm/utility.rs | 3 +- matrix_sdk_crypto/src/requests.rs | 19 +++++++---- matrix_sdk_test/src/lib.rs | 23 +++++++------ matrix_sdk_test/src/test_json/mod.rs | 6 ++-- matrix_sdk_test_macros/src/lib.rs | 3 +- 22 files changed, 139 insertions(+), 105 deletions(-) rename rustfmt.toml => .rustfmt.toml (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bde7757c..e6de8eb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - name: Install rust uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: nightly components: rustfmt profile: minimal override: true diff --git a/rustfmt.toml b/.rustfmt.toml similarity index 100% rename from rustfmt.toml rename to .rustfmt.toml diff --git a/matrix_sdk/examples/command_bot.rs b/matrix_sdk/examples/command_bot.rs index 9beca928..d6c00fda 100644 --- a/matrix_sdk/examples/command_bot.rs +++ b/matrix_sdk/examples/command_bot.rs @@ -73,18 +73,19 @@ async fn login_and_sync( println!("logged in as {}", username); - // An initial sync to set up state and so our bot doesn't respond to old messages. - // If the `StateStore` finds saved state in the location given the initial sync will - // be skipped in favor of loading state from the store + // An initial sync to set up state and so our bot doesn't respond to old + // messages. If the `StateStore` finds saved state in the location given the + // initial sync will be skipped in favor of loading state from the store client.sync_once(SyncSettings::default()).await.unwrap(); - // add our CommandBot to be notified of incoming messages, we do this after the initial - // sync to avoid responding to messages before the bot was running. + // add our CommandBot to be notified of incoming messages, we do this after the + // initial sync to avoid responding to messages before the bot was running. client.set_event_handler(Box::new(CommandBot::new())).await; // since we called `sync_once` before we entered our sync loop we must pass // that sync token to `sync` let settings = SyncSettings::default().token(client.sync_token().await.unwrap()); - // this keeps state from the server streaming in to CommandBot via the EventHandler trait + // this keeps state from the server streaming in to CommandBot via the + // EventHandler trait client.sync(settings).await; Ok(()) diff --git a/matrix_sdk/src/device.rs b/matrix_sdk/src/device.rs index 3f924257..718fcb6f 100644 --- a/matrix_sdk/src/device.rs +++ b/matrix_sdk/src/device.rs @@ -40,7 +40,8 @@ impl Deref for Device { impl Device { /// Start a interactive verification with this `Device` /// - /// Returns a `Sas` object that represents the interactive verification flow. + /// Returns a `Sas` object that represents the interactive verification + /// flow. /// /// # Example /// diff --git a/matrix_sdk/src/event_handler/mod.rs b/matrix_sdk/src/event_handler/mod.rs index fc1e8ae6..754d76bb 100644 --- a/matrix_sdk/src/event_handler/mod.rs +++ b/matrix_sdk/src/event_handler/mod.rs @@ -76,12 +76,7 @@ impl Handler { } pub(crate) async fn handle_sync(&self, response: &SyncResponse) { - for event in response - .account_data - .events - .iter() - .filter_map(|e| e.deserialize().ok()) - { + for event in response.account_data.events.iter().filter_map(|e| e.deserialize().ok()) { self.handle_account_data_event(&event).await; } @@ -95,8 +90,7 @@ impl Handler { for event in room_info.account_data.events.iter().filter_map(|e| e.deserialize().ok()) { - self.handle_room_account_data_event(room.clone(), &event) - .await; + self.handle_room_account_data_event(room.clone(), &event).await; } for event in room_info.state.events.iter().filter_map(|e| e.deserialize().ok()) { @@ -116,8 +110,7 @@ impl Handler { for event in room_info.account_data.events.iter().filter_map(|e| e.deserialize().ok()) { - self.handle_room_account_data_event(room.clone(), &event) - .await; + self.handle_room_account_data_event(room.clone(), &event).await; } for event in room_info.state.events.iter().filter_map(|e| e.deserialize().ok()) { diff --git a/matrix_sdk/src/http_client.rs b/matrix_sdk/src/http_client.rs index 9d7a216d..aced4169 100644 --- a/matrix_sdk/src/http_client.rs +++ b/matrix_sdk/src/http_client.rs @@ -38,13 +38,16 @@ use crate::{ #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait HttpSend: AsyncTraitDeps { - /// The method abstracting sending request types and receiving response types. + /// The method abstracting sending request types and receiving response + /// types. /// - /// This is called by the client every time it wants to send anything to a homeserver. + /// This is called by the client every time it wants to send anything to a + /// homeserver. /// /// # Arguments /// - /// * `request` - The http request that has been converted from a ruma `Request`. + /// * `request` - The http request that has been converted from a ruma + /// `Request`. /// /// * `request_config` - The config used for this request. /// diff --git a/matrix_sdk/src/lib.rs b/matrix_sdk/src/lib.rs index 9ee9fb2a..8b5da4eb 100644 --- a/matrix_sdk/src/lib.rs +++ b/matrix_sdk/src/lib.rs @@ -17,19 +17,21 @@ //! //! # Enabling logging //! -//! Users of the matrix-sdk crate can enable log output by depending on the `tracing-subscriber` -//! crate and including the following line in their application (e.g. at the start of `main`): +//! Users of the matrix-sdk crate can enable log output by depending on the +//! `tracing-subscriber` crate and including the following line in their +//! application (e.g. at the start of `main`): //! //! ```rust //! tracing_subscriber::fmt::init(); //! ``` //! -//! The log output is controlled via the `RUST_LOG` environment variable by setting it to one of -//! the `error`, `warn`, `info`, `debug` or `trace` levels. The output is printed to stdout. +//! The log output is controlled via the `RUST_LOG` environment variable by +//! setting it to one of the `error`, `warn`, `info`, `debug` or `trace` levels. +//! The output is printed to stdout. //! -//! The `RUST_LOG` variable also supports a more advanced syntax for filtering log output more -//! precisely, for instance with crate-level granularity. For more information on this, check out -//! the [tracing_subscriber +//! The `RUST_LOG` variable also supports a more advanced syntax for filtering +//! log output more precisely, for instance with crate-level granularity. For +//! more information on this, check out the [tracing_subscriber //! documentation](https://tracing.rs/tracing_subscriber/filter/struct.envfilter). //! //! # Crate Feature Flags @@ -44,10 +46,13 @@ //! * `markdown`: Support for sending markdown formatted messages. //! * `socks`: Enables SOCKS support in reqwest, the default HTTP client. //! * `sso_login`: Enables SSO login with a local http server. -//! * `require_auth_for_profile_requests`: Whether to send the access token in the authentication -//! header when calling endpoints that retrieve profile data. This matches the synapse -//! configuration `require_auth_for_profile_requests`. Enabled by default. -//! * `appservice`: Enables low-level appservice functionality. For an high-level API there's the +//! * `require_auth_for_profile_requests`: Whether to send the access token in +//! the authentication +//! header when calling endpoints that retrieve profile data. This matches the +//! synapse configuration `require_auth_for_profile_requests`. Enabled by +//! default. +//! * `appservice`: Enables low-level appservice functionality. For an +//! high-level API there's the //! `matrix-sdk-appservice` crate #![deny( diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index 9cd44b45..80526bf2 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -12,7 +12,8 @@ use matrix_sdk_common::{ use crate::{BaseRoom, Client, Result, RoomMember}; -/// A struct containing methodes that are common for Joined, Invited and Left Rooms +/// A struct containing methodes that are common for Joined, Invited and Left +/// Rooms #[derive(Debug, Clone)] pub struct Common { inner: BaseRoom, @@ -108,9 +109,9 @@ impl Common { } } - /// Sends a request to `/_matrix/client/r0/rooms/{room_id}/messages` and returns - /// a `get_message_events::Response` that contains a chunk of room and state events - /// (`AnyRoomEvent` and `AnyStateEvent`). + /// Sends a request to `/_matrix/client/r0/rooms/{room_id}/messages` and + /// returns a `get_message_events::Response` that contains a chunk of + /// room and state events (`AnyRoomEvent` and `AnyStateEvent`). /// /// # Arguments /// @@ -235,9 +236,9 @@ impl Common { /// Get all the joined members of this room. /// - /// *Note*: This method will not fetch the members from the homeserver if the - /// member list isn't synchronized due to member lazy loading. Thus, members - /// could be missing from the list. + /// *Note*: This method will not fetch the members from the homeserver if + /// the member list isn't synchronized due to member lazy loading. Thus, + /// members could be missing from the list. /// /// Use [joined_members()](#method.joined_members) if you want to ensure to /// always get the full member list. @@ -271,9 +272,9 @@ impl Common { /// Get a specific member of this room. /// - /// *Note*: This method will not fetch the members from the homeserver if the - /// member list isn't synchronized due to member lazy loading. Thus, members - /// could be missing. + /// *Note*: This method will not fetch the members from the homeserver if + /// the member list isn't synchronized due to member lazy loading. Thus, + /// members could be missing. /// /// Use [get_member()](#method.get_member) if you want to ensure to always /// have the full member list to chose from. @@ -290,7 +291,8 @@ impl Common { .map(|member| RoomMember::new(self.client.clone(), member))) } - /// Get all members for this room, includes invited, joined and left members. + /// Get all members for this room, includes invited, joined and left + /// members. /// /// *Note*: This method will fetch the members from the homeserver if the /// member list isn't synchronized due to member lazy loading. Because of @@ -303,11 +305,12 @@ impl Common { self.members_no_sync().await } - /// Get all members for this room, includes invited, joined and left members. + /// Get all members for this room, includes invited, joined and left + /// members. /// - /// *Note*: This method will not fetch the members from the homeserver if the - /// member list isn't synchronized due to member lazy loading. Thus, members - /// could be missing. + /// *Note*: This method will not fetch the members from the homeserver if + /// the member list isn't synchronized due to member lazy loading. Thus, + /// members could be missing. /// /// Use [members()](#method.members) if you want to ensure to always get /// the full member list. diff --git a/matrix_sdk/src/room/invited.rs b/matrix_sdk/src/room/invited.rs index aa4c02d5..fc7c1196 100644 --- a/matrix_sdk/src/room/invited.rs +++ b/matrix_sdk/src/room/invited.rs @@ -4,15 +4,17 @@ use crate::{room::Common, BaseRoom, Client, Result, RoomType}; /// A room in the invited state. /// -/// This struct contains all methodes specific to a `Room` with type `RoomType::Invited`. -/// Operations may fail once the underlaying `Room` changes `RoomType`. +/// This struct contains all methodes specific to a `Room` with type +/// `RoomType::Invited`. Operations may fail once the underlaying `Room` changes +/// `RoomType`. #[derive(Debug, Clone)] pub struct Invited { pub(crate) inner: Common, } impl Invited { - /// Create a new `room::Invited` if the underlaying `Room` has type `RoomType::Invited`. + /// Create a new `room::Invited` if the underlaying `Room` has type + /// `RoomType::Invited`. /// /// # Arguments /// * `client` - The client used to make requests. diff --git a/matrix_sdk/src/room/left.rs b/matrix_sdk/src/room/left.rs index 0b8c9dc7..3169f356 100644 --- a/matrix_sdk/src/room/left.rs +++ b/matrix_sdk/src/room/left.rs @@ -6,15 +6,17 @@ use crate::{room::Common, BaseRoom, Client, Result, RoomType}; /// A room in the left state. /// -/// This struct contains all methodes specific to a `Room` with type `RoomType::Left`. -/// Operations may fail once the underlaying `Room` changes `RoomType`. +/// This struct contains all methodes specific to a `Room` with type +/// `RoomType::Left`. Operations may fail once the underlaying `Room` changes +/// `RoomType`. #[derive(Debug, Clone)] pub struct Left { pub(crate) inner: Common, } impl Left { - /// Create a new `room::Left` if the underlaying `Room` has type `RoomType::Left`. + /// Create a new `room::Left` if the underlaying `Room` has type + /// `RoomType::Left`. /// /// # Arguments /// * `client` - The client used to make requests. diff --git a/matrix_sdk_appservice/src/lib.rs b/matrix_sdk_appservice/src/lib.rs index 26bce67b..67b89385 100644 --- a/matrix_sdk_appservice/src/lib.rs +++ b/matrix_sdk_appservice/src/lib.rs @@ -14,12 +14,14 @@ //! Matrix [Application Service] library //! -//! The appservice crate aims to provide a batteries-included experience. That means that we -//! * ship with functionality to configure your webserver crate or simply run the webserver for you +//! The appservice crate aims to provide a batteries-included experience. That +//! means that we +//! * ship with functionality to configure your webserver crate or simply run +//! the webserver for you //! * receive and validate requests from the homeserver correctly //! * allow calling the homeserver with proper virtual user identity assertion -//! * have the goal to have a consistent room state available by leveraging the stores that the -//! matrix-sdk provides +//! * have the goal to have a consistent room state available by leveraging the +//! stores that the matrix-sdk provides //! //! # Quickstart //! @@ -173,8 +175,10 @@ impl Appservice { /// # Arguments /// /// * `homeserver_url` - The homeserver that the client should connect to. - /// * `server_name` - The server name to use when constructing user ids from the localpart. - /// * `registration` - The [Appservice Registration] to use when interacting with the homserver. + /// * `server_name` - The server name to use when constructing user ids from + /// the localpart. + /// * `registration` - The [Appservice Registration] to use when interacting + /// with the homserver. /// /// [Appservice Registration]: https://matrix.org/docs/spec/application_service/r0.1.2#registration pub async fn new( @@ -205,8 +209,9 @@ impl Appservice { /// Get `Client` for the given `localpart` /// - /// If the `localpart` is covered by the `namespaces` in the [registration] all requests to the - /// homeserver will [assert the identity] to the according virtual user. + /// If the `localpart` is covered by the `namespaces` in the [registration] + /// all requests to the homeserver will [assert the identity] to the + /// according virtual user. /// /// [registration]: https://matrix.org/docs/spec/application_service/r0.1.2#registration /// [assert the identity]: @@ -287,7 +292,8 @@ impl Appservice { /// Get the host and port from the registration URL /// - /// If no port is found it falls back to scheme defaults: 80 for http and 443 for https + /// If no port is found it falls back to scheme defaults: 80 for http and + /// 443 for https pub fn get_host_and_port_from_registration(&self) -> Result<(Host, Port)> { let uri = Uri::try_from(&self.registration.url)?; @@ -311,9 +317,11 @@ impl Appservice { actix::get_scope().data(self.clone()) } - /// Convenience method that runs an http server depending on the selected server feature + /// Convenience method that runs an http server depending on the selected + /// server feature /// - /// This is a blocking call that tries to listen on the provided host and port + /// This is a blocking call that tries to listen on the provided host and + /// port pub async fn run(&self, host: impl AsRef, port: impl Into) -> Result<()> { #[cfg(feature = "actix")] { diff --git a/matrix_sdk_appservice/tests/actix.rs b/matrix_sdk_appservice/tests/actix.rs index a0ec7b4c..4bb4b8cd 100644 --- a/matrix_sdk_appservice/tests/actix.rs +++ b/matrix_sdk_appservice/tests/actix.rs @@ -107,8 +107,8 @@ mod actix { let resp = test::call_service(&app, req).await; - // TODO: this should actually return a 401 but is 500 because something in the extractor - // fails + // TODO: this should actually return a 401 but is 500 because something in the + // extractor fails assert_eq!(resp.status(), 500); } } diff --git a/matrix_sdk_base/src/store/sled_store/store_key.rs b/matrix_sdk_base/src/store/sled_store/store_key.rs index 9685b042..734a8d31 100644 --- a/matrix_sdk_base/src/store/sled_store/store_key.rs +++ b/matrix_sdk_base/src/store/sled_store/store_key.rs @@ -75,9 +75,11 @@ pub struct EncryptedEvent { #[derive(Debug, Serialize, Deserialize, PartialEq)] pub enum KdfInfo { Pbkdf2ToChaCha20Poly1305 { - /// The number of PBKDF rounds that were used when deriving the store key. + /// The number of PBKDF rounds that were used when deriving the store + /// key. rounds: u32, - /// The salt that was used when the passphrase was expanded into a store key. + /// The salt that was used when the passphrase was expanded into a store + /// key. kdf_salt: Vec, }, } diff --git a/matrix_sdk_crypto/benches/perf.rs b/matrix_sdk_crypto/benches/perf.rs index 69284929..b2dfb878 100644 --- a/matrix_sdk_crypto/benches/perf.rs +++ b/matrix_sdk_crypto/benches/perf.rs @@ -6,8 +6,9 @@ use std::{fs::File, os::raw::c_int, path::Path}; use criterion::profiler::Profiler; use pprof::ProfilerGuard; -/// Small custom profiler that can be used with Criterion to create a flamegraph for benchmarks. -/// Also see [the Criterion documentation on this][custom-profiler]. +/// Small custom profiler that can be used with Criterion to create a flamegraph +/// for benchmarks. Also see [the Criterion documentation on +/// this][custom-profiler]. /// /// ## Example on how to enable the custom profiler: /// @@ -30,12 +31,12 @@ use pprof::ProfilerGuard; /// } /// ``` /// -/// The neat thing about this is that it will sample _only_ the benchmark, and not other stuff like -/// the setup process. +/// The neat thing about this is that it will sample _only_ the benchmark, and +/// not other stuff like the setup process. /// -/// Further, it will only kick in if `--profile-time