From bfbb55d2286ec3dc2b73a97fd3a0ebe5dd7ef574 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 | 1 - tuta-sdk/rust/sdk/src/user_facade.rs | 4 +++- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/tuta-sdk/rust/demo/src/main.rs b/tuta-sdk/rust/demo/src/main.rs index d06b16316ce4..b04dedaf78f8 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 d0842f5289da..d164bb42faae 100644 --- a/tuta-sdk/rust/sdk/src/lib.rs +++ b/tuta-sdk/rust/sdk/src/lib.rs @@ -44,7 +44,9 @@ pub mod date; mod element_value; mod entities; mod entity_client; +pub mod folder_system; pub mod generated_id; +mod groups; mod instance_mapper; mod json_element; mod json_serializer; @@ -62,8 +64,6 @@ mod type_model_provider; mod typed_entity_client; mod user_facade; mod util; -mod groups; -pub mod folder_system; uniffi::setup_scaffolding!(); diff --git a/tuta-sdk/rust/sdk/src/mail_facade.rs b/tuta-sdk/rust/sdk/src/mail_facade.rs index aeabf6ffb086..7b2f5497162b 100644 --- a/tuta-sdk/rust/sdk/src/mail_facade.rs +++ b/tuta-sdk/rust/sdk/src/mail_facade.rs @@ -2,7 +2,6 @@ use std::sync::Arc; #[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; diff --git a/tuta-sdk/rust/sdk/src/user_facade.rs b/tuta-sdk/rust/sdk/src/user_facade.rs index fb1afa393d2a..d3988b9f1179 100644 --- a/tuta-sdk/rust/sdk/src/user_facade.rs +++ b/tuta-sdk/rust/sdk/src/user_facade.rs @@ -148,7 +148,9 @@ impl GroupMembership { 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) + }, } } }