Skip to content

Commit

Permalink
[sdk] Fix few style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
charlag committed Oct 15, 2024
1 parent 23b848e commit bfbb55d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
9 changes: 7 additions & 2 deletions tuta-sdk/rust/demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
})
}
}
Expand Down Expand Up @@ -100,7 +105,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

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?;

Expand Down
22 changes: 12 additions & 10 deletions tuta-sdk/rust/sdk/src/folder_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MailFolder>) -> Self {
Self { folders }
}

#[must_use]
pub fn system_folder_by_type(&self, mail_set_kind: MailSetKind) -> Option<&MailFolder> {
self.folders
.iter()
Expand Down
4 changes: 3 additions & 1 deletion tuta-sdk/rust/sdk/src/generated_id.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions tuta-sdk/rust/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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!();

Expand Down
1 change: 0 additions & 1 deletion tuta-sdk/rust/sdk/src/mail_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion tuta-sdk/rust/sdk/src/user_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
}

0 comments on commit bfbb55d

Please sign in to comment.