From 45f0aa3d8147efc95d25285481ff4345351e5f65 Mon Sep 17 00:00:00 2001 From: Mauro D Date: Tue, 2 Aug 2022 16:08:08 +0000 Subject: [PATCH] Migrated to AHashMap. --- Cargo.toml | 1 + src/blob/copy.rs | 7 +++-- src/client_ws.rs | 9 ++++--- src/core/copy.rs | 11 ++++---- src/core/request.rs | 8 +++--- src/core/response.rs | 8 +++--- src/core/session.rs | 14 +++++----- src/core/set.rs | 39 +++++++++++++-------------- src/email/import.rs | 22 +++++++-------- src/email/mod.rs | 54 +++++++++---------------------------- src/email/parse.rs | 8 +++--- src/email/set.rs | 18 ++++++------- src/email_submission/get.rs | 8 +++--- src/email_submission/mod.rs | 10 +++---- src/email_submission/set.rs | 10 +++---- src/event_source/mod.rs | 14 +++++----- src/event_source/parser.rs | 4 +-- src/lib.rs | 6 ++--- src/mailbox/get.rs | 10 +++---- src/mailbox/mod.rs | 9 +++---- src/mailbox/set.rs | 12 ++++----- src/principal/get.rs | 8 +++--- src/principal/mod.rs | 6 ++--- src/principal/set.rs | 10 +++---- 24 files changed, 125 insertions(+), 181 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cdedf8b..51d3b12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ base64 = "0.13" tokio-tungstenite = { version = "0.17", features = ["rustls-tls-webpki-roots"], optional = true} tokio = { version = "1.16", default-features = false, features = ["io-util"], optional = true } parking_lot = "0.12.0" +ahash = {version = "0.7.6", features = ["serde"]} [features] default = [] diff --git a/src/blob/copy.rs b/src/blob/copy.rs index 0eb98f5..c8b2584 100644 --- a/src/blob/copy.rs +++ b/src/blob/copy.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; - +use ahash::AHashMap; use serde::{Deserialize, Serialize}; use crate::{ @@ -24,9 +23,9 @@ pub struct CopyBlobResponse { #[serde(rename = "accountId")] account_id: String, #[serde(rename = "copied")] - copied: Option>, + copied: Option>, #[serde(rename = "notCopied")] - not_copied: Option>>, + not_copied: Option>>, } impl CopyBlobRequest { diff --git a/src/client_ws.rs b/src/client_ws.rs index 6f76023..06906c4 100644 --- a/src/client_ws.rs +++ b/src/client_ws.rs @@ -1,5 +1,6 @@ -use std::{collections::HashMap, pin::Pin}; +use std::pin::Pin; +use ahash::AHashMap; use futures_util::{stream::SplitSink, SinkExt, Stream, StreamExt}; use serde::{Deserialize, Serialize}; use tokio::net::TcpStream; @@ -34,7 +35,7 @@ struct WebSocketRequest { #[serde(rename = "createdIds")] #[serde(skip_serializing_if = "Option::is_none")] - created_ids: Option>, + created_ids: Option>, } #[derive(Debug, Deserialize)] @@ -49,7 +50,7 @@ pub struct WebSocketResponse { method_responses: Vec, #[serde(rename = "createdIds")] - created_ids: Option>, + created_ids: Option>, #[serde(rename = "sessionState")] session_state: String, @@ -104,7 +105,7 @@ pub struct WebSocketStateChange { #[serde(rename = "@type")] pub type_: WebSocketStateChangeType, - pub changed: HashMap>, + pub changed: AHashMap>, #[serde(rename = "pushState")] push_state: Option, diff --git a/src/core/copy.rs b/src/core/copy.rs index 07e4bf8..c304374 100644 --- a/src/core/copy.rs +++ b/src/core/copy.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; - +use ahash::AHashMap; use serde::{Deserialize, Serialize}; use crate::Error; @@ -26,7 +25,7 @@ pub struct CopyRequest { if_in_state: Option, #[serde(rename = "create")] - create: HashMap, + create: AHashMap, #[serde(rename = "onSuccessDestroyOriginal")] on_success_destroy_original: bool, @@ -51,10 +50,10 @@ pub struct CopyResponse { new_state: String, #[serde(rename = "created")] - created: Option>, + created: Option>, #[serde(rename = "notCreated")] - not_created: Option>>, + not_created: Option>>, } impl CopyRequest { @@ -64,7 +63,7 @@ impl CopyRequest { if_from_in_state: None, account_id: params.account_id, if_in_state: None, - create: HashMap::new(), + create: AHashMap::new(), on_success_destroy_original: false, destroy_from_if_in_state: None, } diff --git a/src/core/request.rs b/src/core/request.rs index e13c208..3239edf 100644 --- a/src/core/request.rs +++ b/src/core/request.rs @@ -1,7 +1,3 @@ -use std::collections::HashMap; - -use serde::{de::DeserializeOwned, Serialize}; - use crate::{ blob::copy::CopyBlobRequest, client::Client, @@ -18,6 +14,8 @@ use crate::{ vacation_response::VacationResponse, Error, Method, Set, URI, }; +use ahash::AHashMap; +use serde::{de::DeserializeOwned, Serialize}; use super::{ changes::ChangesRequest, @@ -44,7 +42,7 @@ pub struct Request<'x> { #[serde(rename = "createdIds")] #[serde(skip_serializing_if = "Option::is_none")] - pub created_ids: Option>, + pub created_ids: Option>, } #[derive(Debug, Clone, Serialize)] diff --git a/src/core/response.rs b/src/core/response.rs index 38b7194..d1f63b6 100644 --- a/src/core/response.rs +++ b/src/core/response.rs @@ -1,6 +1,6 @@ -use std::{collections::HashMap, fmt}; - +use ahash::AHashMap; use serde::{de::Visitor, Deserialize}; +use std::fmt; use crate::{ blob::copy::CopyBlobResponse, @@ -29,7 +29,7 @@ pub struct Response { method_responses: Vec, #[serde(rename = "createdIds")] - created_ids: Option>, + created_ids: Option>, #[serde(rename = "sessionState")] session_state: String, @@ -40,7 +40,7 @@ pub struct Response { impl Response { pub fn new( method_responses: Vec, - created_ids: Option>, + created_ids: Option>, session_state: String, request_id: Option, ) -> Self { diff --git a/src/core/session.rs b/src/core/session.rs index 0910aae..a6114be 100644 --- a/src/core/session.rs +++ b/src/core/session.rs @@ -1,22 +1,20 @@ -use std::collections::HashMap; - -use serde::{Deserialize, Serialize}; - use crate::{ email::{MailCapabilities, SubmissionCapabilities}, URI, }; +use ahash::AHashMap; +use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Session { #[serde(rename = "capabilities")] - capabilities: HashMap, + capabilities: AHashMap, #[serde(rename = "accounts")] - accounts: HashMap, + accounts: AHashMap, #[serde(rename = "primaryAccounts")] - primary_accounts: HashMap, + primary_accounts: AHashMap, #[serde(rename = "username")] username: String, @@ -49,7 +47,7 @@ pub struct Account { is_read_only: bool, #[serde(rename = "accountCapabilities")] - account_capabilities: HashMap, + account_capabilities: AHashMap, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/core/set.rs b/src/core/set.rs index b8f3025..b969e34 100644 --- a/src/core/set.rs +++ b/src/core/set.rs @@ -1,11 +1,8 @@ +use crate::Error; +use ahash::AHashMap; use chrono::{DateTime, NaiveDateTime, Utc}; use serde::{Deserialize, Serialize}; -use std::{ - collections::HashMap, - fmt::{self, Display, Formatter}, -}; - -use crate::Error; +use std::fmt::{self, Display, Formatter}; use super::{request::ResultReference, Object, RequestParams}; @@ -27,10 +24,10 @@ pub struct SetRequest { if_in_state: Option, #[serde(skip_serializing_if = "Option::is_none")] - create: Option>, + create: Option>, #[serde(skip_serializing_if = "Option::is_none")] - update: Option>, + update: Option>, #[serde(skip_serializing_if = "Option::is_none")] destroy: Option>, @@ -53,25 +50,25 @@ pub struct SetResponse { old_state: Option, #[serde(rename = "newState")] - new_state: String, + new_state: Option, #[serde(rename = "created")] - created: Option>, + created: Option>, #[serde(rename = "updated")] - updated: Option>>, + updated: Option>>, #[serde(rename = "destroyed")] destroyed: Option>, #[serde(rename = "notCreated")] - not_created: Option>>, + not_created: Option>>, #[serde(rename = "notUpdated")] - not_updated: Option>>, + not_updated: Option>>, #[serde(rename = "notDestroyed")] - not_destroyed: Option>>, + not_destroyed: Option>>, } #[derive(Debug, Clone, Deserialize)] @@ -166,7 +163,7 @@ impl SetRequest { let create_id = self.create.as_ref().map_or(0, |c| c.len()); let create_id_str = format!("c{}", create_id); self.create - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(create_id_str.clone(), O::new(create_id.into())); self.create .as_mut() @@ -179,7 +176,7 @@ impl SetRequest { let create_id = self.create.as_ref().map_or(0, |c| c.len()); let create_id_str = format!("c{}", create_id); self.create - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(create_id_str.clone(), item); create_id_str } @@ -187,14 +184,14 @@ impl SetRequest { pub fn update(&mut self, id: impl Into) -> &mut O { let id: String = id.into(); self.update - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(id.clone(), O::new(None)); self.update.as_mut().unwrap().get_mut(&id).unwrap() } pub fn update_item(&mut self, id: impl Into, item: O) { self.update - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(id.into(), item); } @@ -231,11 +228,11 @@ impl SetResponse { } pub fn new_state(&self) -> &str { - self.new_state.as_ref() + self.new_state.as_deref().unwrap_or("") } pub fn take_new_state(&mut self) -> String { - std::mem::take(&mut self.new_state) + self.new_state.take().unwrap_or_default() } pub fn created(&mut self, id: &str) -> crate::Result { @@ -410,6 +407,6 @@ pub fn list_not_set(list: &Option>) -> bool { matches!(list, Some(list) if list.is_empty() ) } -pub fn map_not_set(list: &Option>) -> bool { +pub fn map_not_set(list: &Option>) -> bool { matches!(list, Some(list) if list.is_empty() ) } diff --git a/src/email/import.rs b/src/email/import.rs index e03fbbe..9cdeabc 100644 --- a/src/email/import.rs +++ b/src/email/import.rs @@ -1,8 +1,3 @@ -use std::collections::HashMap; - -use chrono::{DateTime, Utc}; -use serde::{Deserialize, Serialize}; - use crate::{ core::{ request::ResultReference, @@ -11,6 +6,9 @@ use crate::{ }, Error, }; +use ahash::AHashMap; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; use super::{Email, Property}; @@ -23,7 +21,7 @@ pub struct EmailImportRequest { #[serde(skip_serializing_if = "Option::is_none")] if_in_state: Option, - emails: HashMap, + emails: AHashMap, } #[derive(Debug, Clone, Serialize)] @@ -36,7 +34,7 @@ pub struct EmailImport { #[serde(rename = "mailboxIds")] #[serde(skip_serializing_if = "Option::is_none")] - mailbox_ids: Option>, + mailbox_ids: Option>, #[serde(rename = "#mailboxIds")] #[serde(skip_deserializing)] @@ -44,7 +42,7 @@ pub struct EmailImport { mailbox_ids_ref: Option, #[serde(rename = "keywords")] - keywords: HashMap, + keywords: AHashMap, #[serde(rename = "receivedAt")] #[serde(skip_serializing_if = "Option::is_none")] @@ -63,10 +61,10 @@ pub struct EmailImportResponse { new_state: String, #[serde(rename = "created")] - created: Option>, + created: Option>, #[serde(rename = "notCreated")] - not_created: Option>>, + not_created: Option>>, } impl EmailImportRequest { @@ -74,7 +72,7 @@ impl EmailImportRequest { EmailImportRequest { account_id: params.account_id, if_in_state: None, - emails: HashMap::new(), + emails: AHashMap::new(), } } @@ -106,7 +104,7 @@ impl EmailImport { blob_id, mailbox_ids: None, mailbox_ids_ref: None, - keywords: HashMap::new(), + keywords: AHashMap::new(), received_at: None, } } diff --git a/src/email/mod.rs b/src/email/mod.rs index a8a04e4..74e9b43 100644 --- a/src/email/mod.rs +++ b/src/email/mod.rs @@ -5,13 +5,10 @@ pub mod parse; pub mod query; pub mod search_snippet; pub mod set; - +use ahash::AHashMap; use chrono::{DateTime, Utc}; use serde::{de::Visitor, Deserialize, Serialize}; -use std::{ - collections::HashMap, - fmt::{self, Display, Formatter}, -}; +use std::fmt::{self, Display, Formatter}; use crate::{ core::{changes::ChangesObject, request::ResultReference, Object}, @@ -64,7 +61,7 @@ pub struct Email { #[serde(rename = "mailboxIds")] #[serde(skip_serializing_if = "Option::is_none")] - mailbox_ids: Option>, + mailbox_ids: Option>, #[serde(rename = "#mailboxIds")] #[serde(skip_deserializing)] @@ -73,7 +70,7 @@ pub struct Email { #[serde(rename = "keywords")] #[serde(skip_serializing_if = "Option::is_none")] - keywords: Option>, + keywords: Option>, #[serde(rename = "size")] #[serde(skip_serializing_if = "Option::is_none")] @@ -153,7 +150,7 @@ pub struct Email { #[serde(rename = "bodyValues")] #[serde(skip_serializing_if = "Option::is_none")] - body_values: Option>, + body_values: Option>, #[serde(rename = "textBody")] #[serde(skip_serializing_if = "Option::is_none")] @@ -176,13 +173,13 @@ pub struct Email { preview: Option, #[serde(flatten)] - #[serde(skip_serializing_if = "HashMap::is_empty")] - headers: HashMap>, + #[serde(skip_serializing_if = "std::collections::HashMap::is_empty")] + headers: AHashMap>, #[serde(flatten)] #[serde(skip_deserializing)] #[serde(skip_serializing_if = "Option::is_none")] - patch: Option>, + patch: Option>, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -240,7 +237,7 @@ pub struct EmailBodyPart { #[serde(flatten)] #[serde(skip_serializing_if = "Option::is_none")] - header: Option>, + header: Option>, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -948,41 +945,16 @@ impl From for TestEmail { reply_to: email.reply_to, subject: email.subject, sent_at: email.sent_at, - body_structure: email.body_structure.map(|b| b.into_sorted_part().into()), + body_structure: email.body_structure, body_values: email .body_values .map(|body_values| body_values.into_iter().collect()), - text_body: email - .text_body - .map(|parts| parts.into_iter().map(|b| b.into_sorted_part()).collect()), - html_body: email - .html_body - .map(|parts| parts.into_iter().map(|b| b.into_sorted_part()).collect()), - attachments: email - .attachments - .map(|parts| parts.into_iter().map(|b| b.into_sorted_part()).collect()), + text_body: email.text_body, + html_body: email.html_body, + attachments: email.attachments, has_attachment: email.has_attachment, preview: email.preview, headers: email.headers.into_iter().collect(), } } } - -#[cfg(feature = "debug")] -impl EmailBodyPart { - pub fn sort_headers(&mut self) { - if let Some(headers) = self.headers.as_mut() { - headers.sort_unstable_by_key(|h| (h.name.clone(), h.value.clone())); - } - if let Some(subparts) = self.sub_parts.as_mut() { - for sub_part in subparts { - sub_part.sort_headers(); - } - } - } - - pub fn into_sorted_part(mut self) -> Self { - self.sort_headers(); - self - } -} diff --git a/src/email/parse.rs b/src/email/parse.rs index fae436b..a17cacd 100644 --- a/src/email/parse.rs +++ b/src/email/parse.rs @@ -1,10 +1,8 @@ -use std::collections::HashMap; - use serde::{Deserialize, Serialize}; -use crate::{core::RequestParams, Error}; - use super::{BodyProperty, Email, Property}; +use crate::{core::RequestParams, Error}; +use ahash::AHashMap; #[derive(Debug, Clone, Serialize)] pub struct EmailParseRequest { @@ -45,7 +43,7 @@ pub struct EmailParseResponse { account_id: String, #[serde(rename = "parsed")] - parsed: Option>, + parsed: Option>, #[serde(rename = "notParsable")] not_parsable: Option>, diff --git a/src/email/set.rs b/src/email/set.rs index 3db88e3..decc9ad 100644 --- a/src/email/set.rs +++ b/src/email/set.rs @@ -1,5 +1,7 @@ -use std::collections::HashMap; - +use super::{ + Email, EmailAddress, EmailAddressGroup, EmailBodyPart, EmailBodyValue, EmailHeader, Header, + HeaderValue, +}; use crate::{ core::{ request::ResultReference, @@ -7,11 +9,7 @@ use crate::{ }, Get, Set, }; - -use super::{ - Email, EmailAddress, EmailAddressGroup, EmailBodyPart, EmailBodyValue, EmailHeader, Header, - HeaderValue, -}; +use ahash::AHashMap; impl Email { pub fn mailbox_ids(&mut self, mailbox_ids: T) -> &mut Self @@ -33,7 +31,7 @@ impl Email { pub fn mailbox_id(&mut self, mailbox_id: &str, set: bool) -> &mut Self { self.mailbox_ids = None; self.patch - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(format!("mailboxIds/{}", mailbox_id), set); self } @@ -50,7 +48,7 @@ impl Email { pub fn keyword(&mut self, keyword: &str, set: bool) -> &mut Self { self.keywords = None; self.patch - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(format!("keywords/{}", keyword), set); self } @@ -153,7 +151,7 @@ impl Email { pub fn body_value(&mut self, id: String, body_value: impl Into) -> &mut Self { self.body_values - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(id, body_value.into()); self } diff --git a/src/email_submission/get.rs b/src/email_submission/get.rs index cf4883e..5fee320 100644 --- a/src/email_submission/get.rs +++ b/src/email_submission/get.rs @@ -1,8 +1,6 @@ -use std::collections::HashMap; - -use crate::{core::get::GetObject, Get, Set}; - use super::{Address, Delivered, DeliveryStatus, Displayed, EmailSubmission, UndoStatus}; +use crate::{core::get::GetObject, Get, Set}; +use ahash::AHashMap; impl EmailSubmission { pub fn id(&self) -> Option<&str> { @@ -45,7 +43,7 @@ impl EmailSubmission { self.delivery_status.as_ref().and_then(|ds| ds.get(email)) } - pub fn delivery_status(&self) -> Option<&HashMap> { + pub fn delivery_status(&self) -> Option<&AHashMap> { self.delivery_status.as_ref() } diff --git a/src/email_submission/mod.rs b/src/email_submission/mod.rs index a60590a..11028c8 100644 --- a/src/email_submission/mod.rs +++ b/src/email_submission/mod.rs @@ -3,10 +3,10 @@ pub mod helpers; pub mod query; pub mod set; -use std::{collections::HashMap, fmt::Display}; - +use ahash::AHashMap; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; +use std::fmt::Display; use crate::{ core::{changes::ChangesObject, Object}, @@ -18,7 +18,7 @@ use crate::{ pub struct SetArguments { #[serde(rename = "onSuccessUpdateEmail")] #[serde(skip_serializing_if = "Option::is_none")] - on_success_update_email: Option>>, + on_success_update_email: Option>>, #[serde(rename = "onSuccessDestroyEmail")] #[serde(skip_serializing_if = "Option::is_none")] on_success_destroy_email: Option>, @@ -62,7 +62,7 @@ pub struct EmailSubmission { #[serde(rename = "deliveryStatus")] #[serde(skip_serializing_if = "Option::is_none")] - delivery_status: Option>, + delivery_status: Option>, #[serde(rename = "dsnBlobIds")] #[serde(skip_serializing_if = "Option::is_none")] @@ -88,7 +88,7 @@ pub struct Address { _state: std::marker::PhantomData, email: String, - parameters: Option>>, + parameters: Option>>, } #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] diff --git a/src/email_submission/set.rs b/src/email_submission/set.rs index 125ad4a..c3f45a3 100644 --- a/src/email_submission/set.rs +++ b/src/email_submission/set.rs @@ -1,8 +1,6 @@ -use std::collections::HashMap; - -use crate::{core::set::SetObject, email::Email, Get, Set}; - use super::{Address, EmailSubmission, Envelope, SetArguments, UndoStatus}; +use crate::{core::set::SetObject, email::Email, Get, Set}; +use ahash::AHashMap; impl EmailSubmission { pub fn identity_id(&mut self, identity_id: impl Into) -> &mut Self { @@ -97,7 +95,7 @@ impl Address { value: Option>, ) -> Self { self.parameters - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(parameter.into(), value.map(|s| s.into())); self } @@ -155,7 +153,7 @@ impl SetArguments { fn on_success_update_email_(&mut self, id: impl Into) -> &mut Email { let id = id.into(); self.on_success_update_email - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(id.clone(), Email::new(None)); self.on_success_update_email .as_mut() diff --git a/src/event_source/mod.rs b/src/event_source/mod.rs index 7da049f..12bd64e 100644 --- a/src/event_source/mod.rs +++ b/src/event_source/mod.rs @@ -1,11 +1,9 @@ pub mod parser; pub mod stream; -use std::collections::HashMap; - -use serde::{Deserialize, Serialize}; - use crate::{core::session::URLParser, TypeState}; +use ahash::AHashMap; +use serde::{Deserialize, Serialize}; pub enum URLParameter { Types, @@ -27,11 +25,11 @@ impl URLParser for URLParameter { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Changes { id: Option, - changes: HashMap>, + changes: AHashMap>, } impl Changes { - pub fn new(id: Option, changes: HashMap>) -> Self { + pub fn new(id: Option, changes: AHashMap>) -> Self { Self { id, changes } } @@ -39,7 +37,7 @@ impl Changes { self.id.as_deref() } - pub fn account_changes(&mut self, account_id: &str) -> Option> { + pub fn account_changes(&mut self, account_id: &str) -> Option> { self.changes.remove(account_id) } @@ -57,7 +55,7 @@ impl Changes { .any(|changes| changes.contains_key(&type_)) } - pub fn into_inner(self) -> HashMap> { + pub fn into_inner(self) -> AHashMap> { self.changes } diff --git a/src/event_source/parser.rs b/src/event_source/parser.rs index ba5cbcf..562219d 100644 --- a/src/event_source/parser.rs +++ b/src/event_source/parser.rs @@ -93,9 +93,9 @@ impl EventParser { } else { None }, - changes: std::collections::HashMap::from_iter([( + changes: ahash::AHashMap::from_iter([( "ping".to_string(), - std::collections::HashMap::new(), + ahash::AHashMap::new(), )]), })); } diff --git a/src/lib.rs b/src/lib.rs index cd620d5..8bda37a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,9 @@ use crate::core::error::MethodError; use crate::core::error::ProblemDetails; use crate::core::set::SetError; -use std::{collections::HashMap, fmt::Display}; - +use ahash::AHashMap; use serde::{Deserialize, Serialize}; +use std::fmt::Display; pub mod blob; pub mod client; @@ -154,7 +154,7 @@ pub enum StateChangeType { pub struct StateChange { #[serde(rename = "@type")] pub type_: StateChangeType, - pub changed: HashMap>, + pub changed: AHashMap>, } #[derive(Debug, Clone)] diff --git a/src/mailbox/get.rs b/src/mailbox/get.rs index e2c2ce1..4868e87 100644 --- a/src/mailbox/get.rs +++ b/src/mailbox/get.rs @@ -1,8 +1,6 @@ -use std::collections::HashMap; - -use crate::{core::get::GetObject, principal::ACL, Get, Set}; - use super::{Mailbox, MailboxRights, Role}; +use crate::{core::get::GetObject, principal::ACL, Get, Set}; +use ahash::AHashMap; impl Mailbox { pub fn id(&self) -> Option<&str> { @@ -53,11 +51,11 @@ impl Mailbox { self.my_rights.as_ref() } - pub fn acl(&self) -> Option<&HashMap>> { + pub fn acl(&self) -> Option<&AHashMap>> { self.acl.as_ref() } - pub fn take_acl(&mut self) -> Option>> { + pub fn take_acl(&mut self) -> Option>> { self.acl.take() } } diff --git a/src/mailbox/mod.rs b/src/mailbox/mod.rs index 410f48d..76b17ff 100644 --- a/src/mailbox/mod.rs +++ b/src/mailbox/mod.rs @@ -3,16 +3,15 @@ pub mod helpers; pub mod query; pub mod set; -use std::collections::HashMap; -use std::fmt::Display; - use crate::core::changes::ChangesObject; use crate::core::set::{map_not_set, string_not_set}; use crate::core::Object; use crate::mailbox::set::role_not_set; use crate::principal::ACL; use crate::{Get, Set}; +use ahash::AHashMap; use serde::{Deserialize, Serialize}; +use std::fmt::Display; #[derive(Debug, Clone, Serialize, Default)] pub struct SetArguments { @@ -88,12 +87,12 @@ pub struct Mailbox { is_subscribed: Option, #[serde(skip_serializing_if = "map_not_set")] - acl: Option>>, + acl: Option>>, #[serde(flatten)] #[serde(skip_deserializing)] #[serde(skip_serializing_if = "Option::is_none")] - acl_patch: Option>, + acl_patch: Option>, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/mailbox/set.rs b/src/mailbox/set.rs index 42a91b2..1ba84e9 100644 --- a/src/mailbox/set.rs +++ b/src/mailbox/set.rs @@ -1,8 +1,6 @@ -use std::collections::HashMap; - -use crate::{core::set::SetObject, principal::ACL, Get, Set}; - use super::{ACLPatch, Mailbox, Role, SetArguments}; +use crate::{core::set::SetObject, principal::ACL, Get, Set}; +use ahash::AHashMap; impl Mailbox { pub fn name(&mut self, name: impl Into) -> &mut Self { @@ -54,7 +52,7 @@ impl Mailbox { } pub fn acl(&mut self, id: &str, acl: impl IntoIterator) -> &mut Self { - self.acl_patch.get_or_insert_with(HashMap::new).insert( + self.acl_patch.get_or_insert_with(AHashMap::new).insert( format!("acl/{}", id), ACLPatch::Replace(acl.into_iter().collect()), ); @@ -63,7 +61,7 @@ impl Mailbox { pub fn acl_set(&mut self, id: &str, acl: ACL, set: bool) -> &mut Self { self.acl_patch - .get_or_insert_with(HashMap::new) + .get_or_insert_with(AHashMap::new) .insert(format!("acl/{}/{}", id, acl), ACLPatch::Set(set)); self } @@ -91,7 +89,7 @@ impl SetObject for Mailbox { unread_threads: None, my_rights: None, is_subscribed: None, - acl: HashMap::with_capacity(0).into(), + acl: AHashMap::with_capacity(0).into(), acl_patch: None, } } diff --git a/src/principal/get.rs b/src/principal/get.rs index f6faf79..87ccade 100644 --- a/src/principal/get.rs +++ b/src/principal/get.rs @@ -1,8 +1,6 @@ -use std::collections::HashMap; - -use crate::{core::get::GetObject, Get, Set}; - use super::{Principal, Type, ACL, DKIM}; +use crate::{core::get::GetObject, Get, Set}; +use ahash::AHashMap; impl Principal { pub fn id(&self) -> Option<&str> { @@ -57,7 +55,7 @@ impl Principal { self.dkim.as_ref() } - pub fn acl(&self) -> Option<&HashMap>> { + pub fn acl(&self) -> Option<&AHashMap>> { self.acl.as_ref() } } diff --git a/src/principal/mod.rs b/src/principal/mod.rs index e18ee5d..4036fc1 100644 --- a/src/principal/mod.rs +++ b/src/principal/mod.rs @@ -4,9 +4,9 @@ pub mod query; pub mod set; use crate::core::set::{list_not_set, map_not_set, string_not_set}; -use std::{collections::HashMap, fmt::Display}; - +use ahash::AHashMap; use serde::{Deserialize, Serialize}; +use std::fmt::Display; use crate::{ core::{changes::ChangesObject, Object}, @@ -49,7 +49,7 @@ pub struct Principal { #[serde(skip_serializing_if = "list_not_set")] members: Option>, #[serde(skip_serializing_if = "map_not_set")] - acl: Option>>, + acl: Option>>, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Copy)] diff --git a/src/principal/set.rs b/src/principal/set.rs index 3e5f567..8a08cb4 100644 --- a/src/principal/set.rs +++ b/src/principal/set.rs @@ -1,8 +1,6 @@ -use std::collections::HashMap; - -use crate::{core::set::SetObject, Get, Set}; - use super::{Principal, Type, ACL, DKIM}; +use crate::{core::set::SetObject, Get, Set}; +use ahash::AHashMap; impl Principal { pub fn name(&mut self, name: impl Into) -> &mut Self { @@ -50,7 +48,7 @@ impl Principal { self } - pub fn acl(&mut self, acl: Option>>) -> &mut Self { + pub fn acl(&mut self, acl: Option>>) -> &mut Self { self.acl = acl; self } @@ -103,7 +101,7 @@ impl SetObject for Principal { quota: None, picture: "".to_string().into(), members: Vec::with_capacity(0).into(), - acl: HashMap::with_capacity(0).into(), + acl: AHashMap::with_capacity(0).into(), } }