Replace HashMap with BTreeMap

This commit is contained in:
Jonas Platte 2020-04-19 16:48:20 +02:00
parent 6452401add
commit c5689f3da5
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
21 changed files with 64 additions and 61 deletions

View File

@ -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};
```

View File

@ -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<String, Value>,
pub custom_capabilities: BTreeMap<String, Value>,
}
/// 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<String, RoomVersionStability>,
pub available: BTreeMap<String, RoomVersionStability>,
}
/// The stability of a room version

View File

@ -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),

View File

@ -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<UserId, HashMap<DeviceIdOrAllDevices, all::Event>>
pub messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, all::Event>>
}
response {}

View File

@ -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<Algorithm>,
/// Public identity keys.
pub keys: HashMap<AlgorithmAndDeviceId, String>,
pub keys: BTreeMap<AlgorithmAndDeviceId, String>,
/// Signatures for the device key object.
pub signatures: HashMap<UserId, HashMap<AlgorithmAndDeviceId, String>>,
pub signatures: BTreeMap<UserId, BTreeMap<AlgorithmAndDeviceId, String>>,
/// 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<UserId, HashMap<AlgorithmAndDeviceId, String>>,
pub signatures: BTreeMap<UserId, BTreeMap<AlgorithmAndDeviceId, String>>,
}
/// A one-time public key for "pre-key" messages.

View File

@ -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<Duration>,
/// The keys to be claimed.
pub one_time_keys: HashMap<UserId, HashMap<DeviceId, KeyAlgorithm>>,
pub one_time_keys: BTreeMap<UserId, BTreeMap<DeviceId, KeyAlgorithm>>,
}
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<String, Value>,
pub failures: BTreeMap<String, Value>,
/// One-time keys for the queried devices.
pub one_time_keys: HashMap<UserId, HashMap<DeviceId, HashMap<AlgorithmAndDeviceId, OneTimeKey>>>,
pub one_time_keys: BTreeMap<UserId, BTreeMap<DeviceId, BTreeMap<AlgorithmAndDeviceId, OneTimeKey>>>,
}
error: crate::Error

View File

@ -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<Duration>,
/// The keys to be downloaded. An empty list indicates all devices for the corresponding user.
pub device_keys: HashMap<UserId, Vec<DeviceId>>,
pub device_keys: BTreeMap<UserId, Vec<DeviceId>>,
/// 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<String, Value>,
pub failures: BTreeMap<String, Value>,
/// Information on the queried devices.
pub device_keys: HashMap<UserId, HashMap<DeviceId, DeviceKeys>>,
pub device_keys: BTreeMap<UserId, BTreeMap<DeviceId, DeviceKeys>>,
}
error: crate::Error

View File

@ -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<HashMap<AlgorithmAndDeviceId, OneTimeKey>>,
pub one_time_keys: Option<BTreeMap<AlgorithmAndDeviceId, OneTimeKey>>,
}
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<KeyAlgorithm, UInt>
pub one_time_key_counts: BTreeMap<KeyAlgorithm, UInt>
}
error: crate::Error

View File

@ -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<String, HashMap<String, String>>,
pub signatures: BTreeMap<String, BTreeMap<String, String>>,
/// The state key of the m.third_party_invite event.
pub token: String,
}

View File

@ -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<UserId, RoomMember>,
pub joined: BTreeMap<UserId, RoomMember>,
}
error: crate::Error

View File

@ -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 {

View File

@ -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<RuleKind, Vec<PushRule>>
pub global: BTreeMap<RuleKind, Vec<PushRule>>
}
error: crate::Error

View File

@ -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<RuleKind, Vec<PushRule>>,
pub global: BTreeMap<RuleKind, Vec<PushRule>>,
}
error: crate::Error

View File

@ -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<HashMap<UserId, UserProfile>>,
pub profile_info: Option<BTreeMap<UserId, UserProfile>>,
/// 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<GroupingKey, HashMap<RoomId, ResultGroup>>,
pub groups: BTreeMap<GroupingKey, BTreeMap<RoomId, ResultGroup>>,
/// 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")]

View File

@ -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<String, DeviceInfo>,
pub devices: BTreeMap<String, DeviceInfo>,
}
error: crate::Error

View File

@ -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<DeviceLists>,
/// 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<KeyAlgorithm, UInt>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub device_one_time_keys_count: BTreeMap<KeyAlgorithm, UInt>,
}
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<RoomId, LeftRoom>,
pub leave: BTreeMap<RoomId, LeftRoom>,
/// The rooms that the user has joined.
#[wrap_incoming(JoinedRoom)]
pub join: HashMap<RoomId, JoinedRoom>,
pub join: BTreeMap<RoomId, JoinedRoom>,
/// The rooms that the user has been invited to.
#[wrap_incoming(InvitedRoom)]
pub invite: HashMap<RoomId, InvitedRoom>,
pub invite: BTreeMap<RoomId, InvitedRoom>,
}
/// Historical updates to left rooms.

View File

@ -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<String, FieldType>,
pub field_types: BTreeMap<String, FieldType>,
/// A list of objects representing independent instances of configuration.
pub instances: Vec<ProtocolInstance>,
}
@ -37,7 +37,7 @@ pub struct ProtocolInstance {
#[serde(skip_serializing_if = "Option::is_none")]
pub icon: Option<String>,
/// Preset values for `fields` the client may use to search by.
pub fields: HashMap<String, String>,
pub fields: BTreeMap<String, String>,
/// 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<String, String>,
pub fields: BTreeMap<String, String>,
}
/// 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<String, String>,
pub fields: BTreeMap<String, String>,
}
/// The medium of a third party identifier.

View File

@ -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<String, String>,
pub fields: BTreeMap<String, String>,
}
response {

View File

@ -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<String, Protocol>,
pub protocols: BTreeMap<String, Protocol>,
}
error: crate::Error

View File

@ -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<String, String>,
pub fields: BTreeMap<String, String>,
}
response {

View File

@ -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<String>,
/// Experimental features supported by the server.
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub unstable_features: HashMap<String, bool>
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub unstable_features: BTreeMap<String, bool>
}
error: crate::Error