From c5689f3da579bd0c68e8c5e10daa594db9ecb102 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 16:48:20 +0200 Subject: [PATCH] Replace HashMap with BTreeMap --- CONTRIBUTING.md | 6 +++--- src/r0/capabilities/get_capabilities.rs | 6 +++--- src/r0/client_exchange.rs | 3 ++- src/r0/client_exchange/send_event_to_device.rs | 4 ++-- src/r0/keys.rs | 12 ++++++------ src/r0/keys/claim_keys.rs | 8 ++++---- src/r0/keys/get_keys.rs | 8 ++++---- src/r0/keys/upload_keys.rs | 6 +++--- src/r0/membership.rs | 4 ++-- src/r0/membership/joined_members.rs | 4 ++-- src/r0/push.rs | 4 +++- src/r0/push/get_pushrules_all.rs | 4 ++-- src/r0/push/get_pushrules_global_scope.rs | 4 ++-- src/r0/search/search_events.rs | 8 ++++---- src/r0/server/get_user_info.rs | 4 ++-- src/r0/sync/sync_events.rs | 12 ++++++------ src/r0/thirdparty.rs | 10 +++++----- src/r0/thirdparty/get_location_for_protocol.rs | 4 ++-- src/r0/thirdparty/get_protocols.rs | 4 ++-- src/r0/thirdparty/get_user_for_protocol.rs | 4 ++-- src/unversioned/get_supported_versions.rs | 6 +++--- 21 files changed, 64 insertions(+), 61 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 46856b78..fbe97a77 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,7 +60,7 @@ Organize your imports into three groups separated by blank lines: For example, ```rust -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -71,7 +71,7 @@ Also, group imports by module. For example, do this: ```rust use std::{ - collections::HashMap, + collections::BTreeMap, convert::TryFrom, fmt::{Debug, Display, Error as FmtError, Formatter}, }; @@ -80,7 +80,7 @@ use std::{ as opposed to: ```rust -use std::collections::HashMap; +use std::collections::BTreeMap; use std::convert::TryFrom; use std::fmt::{Debug, Display, Error as FmtError, Formatter}; ``` diff --git a/src/r0/capabilities/get_capabilities.rs b/src/r0/capabilities/get_capabilities.rs index 9345280c..d0d97cca 100644 --- a/src/r0/capabilities/get_capabilities.rs +++ b/src/r0/capabilities/get_capabilities.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::collections::HashMap; +use std::collections::BTreeMap; ruma_api! { metadata { @@ -39,7 +39,7 @@ pub struct Capabilities { /// Any other custom capabilities that the server supports outside of the specification, /// labeled using the Java package naming convention and stored as arbitrary JSON values. #[serde(flatten)] - pub custom_capabilities: HashMap, + pub custom_capabilities: BTreeMap, } /// Information about the m.change_password capability @@ -56,7 +56,7 @@ pub struct RoomVersionsCapability { pub default: String, /// A detailed description of the room versions the server supports. - pub available: HashMap, + pub available: BTreeMap, } /// The stability of a room version diff --git a/src/r0/client_exchange.rs b/src/r0/client_exchange.rs index 033d0fd1..6e68ce68 100644 --- a/src/r0/client_exchange.rs +++ b/src/r0/client_exchange.rs @@ -12,8 +12,9 @@ use serde::{ }; pub mod send_event_to_device; + /// Represents one or all of a user's devices. -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum DeviceIdOrAllDevices { /// Represents a device Id for one of a user's devices. DeviceId(DeviceId), diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs index afef7244..d1cace11 100644 --- a/src/r0/client_exchange/send_event_to_device.rs +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -1,6 +1,6 @@ //! [PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-sendtodevice-eventtype-txnid) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_events::{collections::all, EventResult}; @@ -29,7 +29,7 @@ ruma_api! { /// device. Individual message events can be sent to devices, but all /// events must be of the same type. #[wrap_incoming(all::Event with EventResult)] - pub messages: HashMap> + pub messages: BTreeMap> } response {} diff --git a/src/r0/keys.rs b/src/r0/keys.rs index 1fc91089..1d14d27d 100644 --- a/src/r0/keys.rs +++ b/src/r0/keys.rs @@ -1,7 +1,7 @@ //! Endpoints for key management use std::{ - collections::HashMap, + collections::BTreeMap, convert::TryFrom, fmt::{Debug, Display, Error as FmtError, Formatter}, }; @@ -19,7 +19,7 @@ pub mod get_keys; pub mod upload_keys; /// The basic key algorithms in the specification -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub enum KeyAlgorithm { /// The Ed25519 signature algorithm. #[serde(rename = "ed25519")] @@ -59,7 +59,7 @@ impl TryFrom<&'_ str> for KeyAlgorithm { } /// A key algorithm and a device id, combined with a ':' -#[derive(Debug, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct AlgorithmAndDeviceId(pub KeyAlgorithm, pub DeviceId); impl Serialize for AlgorithmAndDeviceId { @@ -116,9 +116,9 @@ pub struct DeviceKeys { /// The encryption algorithms supported by this device. pub algorithms: Vec, /// Public identity keys. - pub keys: HashMap, + pub keys: BTreeMap, /// Signatures for the device key object. - pub signatures: HashMap>, + pub signatures: BTreeMap>, /// Additional data added to the device key information by intermediate servers, and /// not covered by the signatures. #[serde(skip_serializing_if = "Option::is_none")] @@ -138,7 +138,7 @@ pub struct SignedKey { /// Base64-encoded 32-byte Curve25519 public key. pub key: String, /// Signatures for the key object. - pub signatures: HashMap>, + pub signatures: BTreeMap>, } /// A one-time public key for "pre-key" messages. diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs index 70b5a7ec..8a2d7cd2 100644 --- a/src/r0/keys/claim_keys.rs +++ b/src/r0/keys/claim_keys.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/keys/claim](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-claim) -use std::collections::HashMap; +use std::collections::BTreeMap; use std::time::Duration; @@ -31,16 +31,16 @@ ruma_api! { pub timeout: Option, /// The keys to be claimed. - pub one_time_keys: HashMap>, + pub one_time_keys: BTreeMap>, } response { /// If any remote homeservers could not be reached, they are recorded here. /// The names of the properties are the names of the unreachable servers. - pub failures: HashMap, + pub failures: BTreeMap, /// One-time keys for the queried devices. - pub one_time_keys: HashMap>>, + pub one_time_keys: BTreeMap>>, } error: crate::Error diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index b9e3ecb4..64032e30 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/keys/query](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-query) -use std::{collections::HashMap, time::Duration}; +use std::{collections::BTreeMap, time::Duration}; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; @@ -29,7 +29,7 @@ ruma_api! { pub timeout: Option, /// The keys to be downloaded. An empty list indicates all devices for the corresponding user. - pub device_keys: HashMap>, + pub device_keys: BTreeMap>, /// If the client is fetching keys as a result of a device update received in a sync request, /// this should be the 'since' token of that sync request, or any later sync token. @@ -41,10 +41,10 @@ ruma_api! { response { /// If any remote homeservers could not be reached, they are recorded here. /// The names of the properties are the names of the unreachable servers. - pub failures: HashMap, + pub failures: BTreeMap, /// Information on the queried devices. - pub device_keys: HashMap>, + pub device_keys: BTreeMap>, } error: crate::Error diff --git a/src/r0/keys/upload_keys.rs b/src/r0/keys/upload_keys.rs index d99074b6..95224f3c 100644 --- a/src/r0/keys/upload_keys.rs +++ b/src/r0/keys/upload_keys.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/keys/upload](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-upload) -use std::collections::HashMap; +use std::collections::BTreeMap; use js_int::UInt; use ruma_api::ruma_api; @@ -24,13 +24,13 @@ ruma_api! { /// One-time public keys for "pre-key" messages. #[serde(skip_serializing_if = "Option::is_none")] - pub one_time_keys: Option>, + pub one_time_keys: Option>, } response { /// For each key algorithm, the number of unclaimed one-time keys of that /// type currently held on the server for this device. - pub one_time_key_counts: HashMap + pub one_time_key_counts: BTreeMap } error: crate::Error diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 03af3e75..ce885afb 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -12,7 +12,7 @@ pub mod kick_user; pub mod leave_room; pub mod unban_user; -use std::collections::HashMap; +use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; @@ -27,7 +27,7 @@ pub struct ThirdPartySigned { /// The Matrix ID of the user who issued the invite. pub sender: String, /// A signatures object containing a signature of the entire signed object. - pub signatures: HashMap>, + pub signatures: BTreeMap>, /// The state key of the m.third_party_invite event. pub token: String, } diff --git a/src/r0/membership/joined_members.rs b/src/r0/membership/joined_members.rs index e4727d27..f853af60 100644 --- a/src/r0/membership/joined_members.rs +++ b/src/r0/membership/joined_members.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/joined_members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-joined-members) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -25,7 +25,7 @@ ruma_api! { response { /// A list of the rooms the user is in, i.e. /// the ID of each room in which the user has joined membership. - pub joined: HashMap, + pub joined: BTreeMap, } error: crate::Error diff --git a/src/r0/push.rs b/src/r0/push.rs index d1856ff3..28bd0d16 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -27,7 +27,9 @@ pub mod set_pushrule_actions; pub mod set_pushrule_enabled; /// The kinds of push rules that are available -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Display, EnumString)] +#[derive( + Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Display, EnumString, +)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] pub enum RuleKind { diff --git a/src/r0/push/get_pushrules_all.rs b/src/r0/push/get_pushrules_all.rs index 6954811f..ac08ddfe 100644 --- a/src/r0/push/get_pushrules_all.rs +++ b/src/r0/push/get_pushrules_all.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/pushrules/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -20,7 +20,7 @@ ruma_api! { response { /// The global ruleset - pub global: HashMap> + pub global: BTreeMap> } error: crate::Error diff --git a/src/r0/push/get_pushrules_global_scope.rs b/src/r0/push/get_pushrules_global_scope.rs index fbefecfc..5857e64e 100644 --- a/src/r0/push/get_pushrules_global_scope.rs +++ b/src/r0/push/get_pushrules_global_scope.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/pushrules/global/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -21,7 +21,7 @@ ruma_api! { response { /// The global ruleset. #[ruma_api(body)] - pub global: HashMap>, + pub global: BTreeMap>, } error: crate::Error diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 441cb58e..74cb80ea 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/search](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-search) -use std::collections::HashMap; +use std::collections::BTreeMap; use js_int::UInt; use ruma_api::{ruma_api, Outgoing}; @@ -102,7 +102,7 @@ pub struct EventContextResult { /// The historic profile information of the users that sent the events returned. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] - pub profile_info: Option>, + pub profile_info: Option>, /// Pagination token for the start of the chunk. pub start: String, } @@ -115,7 +115,7 @@ pub struct Grouping { } /// The key within events to use for this grouping. -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(rename_all = "snake_case")] pub enum GroupingKey { /// `room_id` @@ -172,7 +172,7 @@ pub struct RoomEventResults { pub count: UInt, /// Any groups that were requested. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 - pub groups: HashMap>, + pub groups: BTreeMap>, /// Token that can be used to get the next batch of results, by passing as the `next_batch` /// parameter to the next call. If this field is absent, there are no more results. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index 5c3a5dd9..5b06a70e 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-admin-whois-userid) -use std::{collections::HashMap, time::SystemTime}; +use std::{collections::BTreeMap, time::SystemTime}; use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -26,7 +26,7 @@ ruma_api! { /// The Matrix user ID of the user. pub user_id: UserId, /// A map of the user's device identifiers to information about that device. - pub devices: HashMap, + pub devices: BTreeMap, } error: crate::Error diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index cb6200e2..49d47a7e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-sync) -use std::{collections::HashMap, time::Duration}; +use std::{collections::BTreeMap, time::Duration}; use js_int::UInt; use ruma_api::{ruma_api, Outgoing}; @@ -79,8 +79,8 @@ ruma_api! { pub device_lists: Option, /// For each key algorithm, the number of unclaimed one-time keys /// currently held on the server for a device. - #[serde(default, skip_serializing_if = "HashMap::is_empty")] - pub device_one_time_keys_count: HashMap, + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub device_one_time_keys_count: BTreeMap, } error: crate::Error @@ -131,13 +131,13 @@ pub enum Filter { pub struct Rooms { /// The rooms that the user has left or been banned from. #[wrap_incoming(LeftRoom)] - pub leave: HashMap, + pub leave: BTreeMap, /// The rooms that the user has joined. #[wrap_incoming(JoinedRoom)] - pub join: HashMap, + pub join: BTreeMap, /// The rooms that the user has been invited to. #[wrap_incoming(InvitedRoom)] - pub invite: HashMap, + pub invite: BTreeMap, } /// Historical updates to left rooms. diff --git a/src/r0/thirdparty.rs b/src/r0/thirdparty.rs index ad0796a9..99a3566f 100644 --- a/src/r0/thirdparty.rs +++ b/src/r0/thirdparty.rs @@ -7,7 +7,7 @@ pub mod get_protocols; pub mod get_user_for_protocol; pub mod get_user_for_user_id; -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_identifiers::{RoomAliasId, UserId}; @@ -23,7 +23,7 @@ pub struct Protocol { /// A content URI representing an icon for the third party protocol. pub icon: String, /// The type definitions for the fields defined in `user_fields` and `location_fields`. - pub field_types: HashMap, + pub field_types: BTreeMap, /// A list of objects representing independent instances of configuration. pub instances: Vec, } @@ -37,7 +37,7 @@ pub struct ProtocolInstance { #[serde(skip_serializing_if = "Option::is_none")] pub icon: Option, /// Preset values for `fields` the client may use to search by. - pub fields: HashMap, + pub fields: BTreeMap, /// A unique identifier across all instances. pub network_id: String, } @@ -59,7 +59,7 @@ pub struct Location { /// The protocol ID that the third party location is a part of. pub protocol: String, /// Information used to identify this third party location. - pub fields: HashMap, + pub fields: BTreeMap, } /// A third party network user. @@ -70,7 +70,7 @@ pub struct User { /// The protocol ID that the third party user is a part of. pub protocol: String, /// Information used to identify this third party user. - pub fields: HashMap, + pub fields: BTreeMap, } /// The medium of a third party identifier. diff --git a/src/r0/thirdparty/get_location_for_protocol.rs b/src/r0/thirdparty/get_location_for_protocol.rs index 7cf5633c..e0c30b17 100644 --- a/src/r0/thirdparty/get_location_for_protocol.rs +++ b/src/r0/thirdparty/get_location_for_protocol.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/thirdparty/location/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-location-protocol) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -23,7 +23,7 @@ ruma_api! { /// One or more custom fields to help identify the third party location. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] - pub fields: HashMap, + pub fields: BTreeMap, } response { diff --git a/src/r0/thirdparty/get_protocols.rs b/src/r0/thirdparty/get_protocols.rs index e563ab61..aad510f1 100644 --- a/src/r0/thirdparty/get_protocols.rs +++ b/src/r0/thirdparty/get_protocols.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/thirdparty/protocols](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-protocols) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -21,7 +21,7 @@ ruma_api! { response { /// Metadata about protocols supported by the homeserver. #[ruma_api(body)] - pub protocols: HashMap, + pub protocols: BTreeMap, } error: crate::Error diff --git a/src/r0/thirdparty/get_user_for_protocol.rs b/src/r0/thirdparty/get_user_for_protocol.rs index 557f1232..ab9c74a1 100644 --- a/src/r0/thirdparty/get_user_for_protocol.rs +++ b/src/r0/thirdparty/get_user_for_protocol.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/thirdparty/user/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-user-protocol) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -23,7 +23,7 @@ ruma_api! { /// One or more custom fields that are passed to the AS to help identify the user. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] - pub fields: HashMap, + pub fields: BTreeMap, } response { diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index b8fc8308..874c334a 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-versions) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -20,8 +20,8 @@ ruma_api! { /// A list of Matrix client API protocol versions supported by the homeserver. pub versions: Vec, /// Experimental features supported by the server. - #[serde(default, skip_serializing_if = "HashMap::is_empty")] - pub unstable_features: HashMap + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub unstable_features: BTreeMap } error: crate::Error