From 2d51240008cb17197de36fdc94655eb5f47ce702 Mon Sep 17 00:00:00 2001 From: ivk Date: Tue, 15 Oct 2024 09:51:04 +0200 Subject: [PATCH] [sdk] Fix few style issues --- tuta-sdk/rust/demo/src/main.rs | 9 +++++++-- tuta-sdk/rust/sdk/src/folder_system.rs | 22 ++++++++++++---------- tuta-sdk/rust/sdk/src/generated_id.rs | 4 +++- tuta-sdk/rust/sdk/src/lib.rs | 4 ++-- tuta-sdk/rust/sdk/src/mail_facade.rs | 3 +-- tuta-sdk/rust/sdk/src/user_facade.rs | 5 ++++- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tuta-sdk/rust/demo/src/main.rs b/tuta-sdk/rust/demo/src/main.rs index c6f19fa0303c..2df1c41e4cc1 100644 --- a/tuta-sdk/rust/demo/src/main.rs +++ b/tuta-sdk/rust/demo/src/main.rs @@ -62,7 +62,12 @@ impl ReqwestHttpClient { Ok(RestResponse { status: res.status().as_u16() as u32, headers: ret_headers, - body: Some(res.bytes().await.expect("assuming response has a body").into()), + body: Some( + res.bytes() + .await + .expect("assuming response has a body") + .into(), + ), }) } } @@ -100,7 +105,7 @@ async fn main() -> Result<(), Box> { let folders = mail_facade.load_folders_for_mailbox(&mailbox).await?; let inbox = folders - .system_folder_by_type(MailSetKind::INBOX) + .system_folder_by_type(MailSetKind::Inbox) .expect("inbox exists"); let inbox_mails = mail_facade.load_mails_in_folder(inbox).await?; diff --git a/tuta-sdk/rust/sdk/src/folder_system.rs b/tuta-sdk/rust/sdk/src/folder_system.rs index cc87e80957c1..4b18669e9dc4 100644 --- a/tuta-sdk/rust/sdk/src/folder_system.rs +++ b/tuta-sdk/rust/sdk/src/folder_system.rs @@ -9,28 +9,30 @@ pub struct FolderSystem { #[derive(PartialEq, TryFromPrimitive)] #[repr(u64)] pub enum MailSetKind { - CUSTOM = 0, - INBOX = 1, - SENT = 2, - TRASH = 3, - ARCHIVE = 4, - SPAM = 5, - DRAFT = 6, - ALL = 7, - UNKNOWN = 9999, + Custom = 0, + Inbox = 1, + Sent = 2, + Trash = 3, + Archive = 4, + Spam = 5, + Draft = 6, + All = 7, + Unknown = 9999, } impl MailFolder { fn mail_set_kind(&self) -> MailSetKind { - MailSetKind::try_from(self.folderType as u64).unwrap_or(MailSetKind::UNKNOWN) + MailSetKind::try_from(self.folderType as u64).unwrap_or(MailSetKind::Unknown) } } impl FolderSystem { + #[must_use] pub fn new(folders: Vec) -> Self { Self { folders } } + #[must_use] pub fn system_folder_by_type(&self, mail_set_kind: MailSetKind) -> Option<&MailFolder> { self.folders .iter() diff --git a/tuta-sdk/rust/sdk/src/generated_id.rs b/tuta-sdk/rust/sdk/src/generated_id.rs index 8ff3101442f2..1c45aec52cc6 100644 --- a/tuta-sdk/rust/sdk/src/generated_id.rs +++ b/tuta-sdk/rust/sdk/src/generated_id.rs @@ -1,7 +1,7 @@ -use std::borrow::ToOwned; use crate::entity_client::IdType; use serde::de::{Error, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use std::borrow::ToOwned; use std::fmt::{Debug, Display, Formatter}; pub const GENERATED_ID_STRUCT_NAME: &str = "GeneratedId"; @@ -27,11 +27,13 @@ impl GeneratedId { Self(generate_random_string::<9>()) } + #[must_use] pub fn min_id() -> Self { // ideally should return a ref to a static id GeneratedId("------------".to_owned()) } + #[must_use] pub fn max_id() -> Self { // ideally should return a ref to a static id GeneratedId("zzzzzzzzzzzz".to_owned()) diff --git a/tuta-sdk/rust/sdk/src/lib.rs b/tuta-sdk/rust/sdk/src/lib.rs index b4b7705cff56..45b1e451f249 100644 --- a/tuta-sdk/rust/sdk/src/lib.rs +++ b/tuta-sdk/rust/sdk/src/lib.rs @@ -53,7 +53,9 @@ pub mod date; mod element_value; pub mod entities; mod entity_client; +pub mod folder_system; pub mod generated_id; +mod groups; mod instance_mapper; mod json_element; mod json_serializer; @@ -75,8 +77,6 @@ mod type_model_provider; mod typed_entity_client; mod user_facade; mod util; -mod groups; -pub mod folder_system; pub static CLIENT_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/tuta-sdk/rust/sdk/src/mail_facade.rs b/tuta-sdk/rust/sdk/src/mail_facade.rs index 6f41184e6ac6..2f0e8a19cfe9 100644 --- a/tuta-sdk/rust/sdk/src/mail_facade.rs +++ b/tuta-sdk/rust/sdk/src/mail_facade.rs @@ -1,15 +1,14 @@ use std::sync::Arc; -use crate::{ApiCallError, IdTuple, ListLoadDirection}; #[cfg_attr(test, mockall_double::double)] use crate::crypto_entity_client::CryptoEntityClient; -use crate::entities::sys::GroupMembership; use crate::entities::tutanota::{Mail, MailBox, MailFolder, MailboxGroupRoot}; use crate::folder_system::FolderSystem; use crate::generated_id::GeneratedId; use crate::groups::GroupType; #[cfg_attr(test, mockall_double::double)] use crate::user_facade::UserFacade; +use crate::{ApiCallError, IdTuple, ListLoadDirection}; /// Provides high level functions to manipulate mail entities via the REST API #[derive(uniffi::Object)] diff --git a/tuta-sdk/rust/sdk/src/user_facade.rs b/tuta-sdk/rust/sdk/src/user_facade.rs index 66719317c37c..625caf28a8d0 100644 --- a/tuta-sdk/rust/sdk/src/user_facade.rs +++ b/tuta-sdk/rust/sdk/src/user_facade.rs @@ -145,10 +145,13 @@ impl UserFacade { } impl GroupMembership { + #[must_use] pub fn group_type(&self) -> GroupType { match self.groupType { None => GroupType::Unknown, - Some(groupType) => GroupType::try_from(groupType as u64).unwrap_or(GroupType::Unknown), + Some(group_type) => { + GroupType::try_from(group_type as u64).unwrap_or(GroupType::Unknown) + }, } } }