Use iterators for Flag::from_strs()

This commit is contained in:
Todd Mortimer 2021-04-07 18:09:46 -04:00
parent 11adcfc97b
commit 5942553e7d
3 changed files with 10 additions and 8 deletions

View file

@ -109,7 +109,7 @@ pub fn parse_fetches(
use imap_proto::AttributeValue;
match attr {
AttributeValue::Flags(flags) => {
fetch.flags.extend(Flag::from_vec(flags));
fetch.flags.extend(Flag::from_strs(flags));
}
AttributeValue::Uid(uid) => fetch.uid = Some(*uid),
AttributeValue::Rfc822Size(sz) => fetch.size = Some(*sz),
@ -269,7 +269,7 @@ pub fn parse_mailbox(
mailbox.unseen = Some(n);
}
Some(ResponseCode::PermanentFlags(flags)) => {
mailbox.permanent_flags.extend(Flag::from_vec(&flags));
mailbox.permanent_flags.extend(Flag::from_strs(flags));
}
_ => {}
}
@ -293,7 +293,7 @@ pub fn parse_mailbox(
mailbox.recent = r;
}
MailboxDatum::Flags(flags) => {
mailbox.flags.extend(Flag::from_vec(&flags));
mailbox.flags.extend(Flag::from_strs(flags));
}
_ => {}
}

View file

@ -169,9 +169,11 @@ impl Flag<'static> {
}
}
/// Helper function to transform a [`Vec`] of flag strings into a [`Vec`] of [`Flag`].
pub fn from_vec<S: ToString>(v: &[S]) -> Vec<Self> {
v.iter().map(|s| Self::from(s.to_string())).collect()
/// Helper function to transform Strings into owned Flags
pub fn from_strs<S: ToString>(
v: impl IntoIterator<Item = S>,
) -> impl Iterator<Item = Flag<'static>> {
v.into_iter().map(|s| Flag::from(s.to_string()))
}
}

View file

@ -173,7 +173,7 @@ impl<'a> TryFrom<Response<'a>> for UnsolicitedResponse {
}
Response::MailboxData(MailboxDatum::Recent(n)) => Ok(UnsolicitedResponse::Recent(n)),
Response::MailboxData(MailboxDatum::Flags(flags)) => {
Ok(UnsolicitedResponse::Flags(Flag::from_vec(&flags)))
Ok(UnsolicitedResponse::Flags(Flag::from_strs(flags).collect()))
}
Response::MailboxData(MailboxDatum::Exists(n)) => Ok(UnsolicitedResponse::Exists(n)),
Response::MailboxData(MailboxDatum::MetadataUnsolicited { mailbox, values }) => {
@ -288,7 +288,7 @@ impl<'a> TryFrom<&ImapProtoAttributeValue<'a>> for AttributeValue {
fn try_from(val: &ImapProtoAttributeValue<'a>) -> Result<Self, Self::Error> {
match val {
ImapProtoAttributeValue::Flags(flags) => {
Ok(AttributeValue::Flags(Flag::from_vec(&flags)))
Ok(AttributeValue::Flags(Flag::from_strs(flags).collect()))
}
ImapProtoAttributeValue::ModSeq(seq) => Ok(AttributeValue::ModSeq(*seq)),
ImapProtoAttributeValue::Uid(uid) => Ok(AttributeValue::Uid(*uid)),