-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sdk range request #7489
Sdk range request #7489
Conversation
4fc7d82
to
2c07623
Compare
2c07623
to
66eee21
Compare
423d273
to
436fe35
Compare
|
||
impl MailFolder { | ||
fn mail_set_kind(&self) -> MailSetKind { | ||
MailSetKind::try_from(self.folderType as u64).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could break if we add more MailSetKind types, and it won't be nice to debug. I'd do one of these two things:
expect("Invalid mail set kind")
if this is not going to happenunwrap_or(MailSetKind::CUSTOM)
if it is a possibility
tuta-sdk/rust/sdk/src/mail_facade.rs
Outdated
.memberships | ||
.iter() | ||
.find(|m| m.groupType == Some(GroupType::Mail.raw_value() as i64)) | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a little cautious around unwrapping based on data provided by the server.
I don't think there will ever be an instance where we won't have a Mail group, but just in case, I'd maybe use expect("User is not part of a mail group")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these mail functions are not production ready yet but you are right, we should harden them a bit
tuta-sdk/rust/sdk/src/groups.rs
Outdated
} | ||
|
||
impl GroupType { | ||
pub fn raw_value(&self) -> u64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For field-less enums, you can use the as
operator instead of trying to match
every variant. You can also derive Copy
/Clone
so that you can pass by value without needing to call .clone()
or create a reference.
Additionally, you can manually specify what each variant is equal to.
Example:
#[repr(u64)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum GroupType {
User = 0,
Admin = 1,
MailingList = 2,
// etc
}
impl GroupType {
pub fn raw_value(self) -> u64 {
self as u64
}
}
assert_eq!(2, GroupType::MailingList as u64);
assert_eq!(2, GroupType::MailingList.raw_value());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you're also using num_enum, too, which could also be what you want.
436fe35
to
711e817
Compare
Should be better now! thank you for the suggestions (I amended one syntax issue) |
6c4be24
to
bfbb55d
Compare
8dd00f4
to
1c49d5e
Compare
1c49d5e
to
2d51240
Compare
2d51240
to
827d5c8
Compare
(stacked on top of #7438
#7679