diff --git a/src/types/fetch.rs b/src/types/fetch.rs index c1872cb..9d497dc 100644 --- a/src/types/fetch.rs +++ b/src/types/fetch.rs @@ -213,4 +213,15 @@ impl<'a> Fetch<'a> { _ => None, }) } + + /// Get an owned copy of the [`Fetch`]. + pub fn into_owned(self) -> Fetch<'static> { + Fetch { + message: self.message, + uid: self.uid, + size: self.size, + fetch: self.fetch.into_iter().map(|av| av.into_owned()).collect(), + flags: self.flags.clone(), + } + } } diff --git a/src/types/flag.rs b/src/types/flag.rs index fed41ec..a1bb9a9 100644 --- a/src/types/flag.rs +++ b/src/types/flag.rs @@ -72,6 +72,22 @@ impl Flag<'static> { } } +impl<'a> Flag<'a> { + /// Get an owned version of the [`Flag`]. + pub fn into_owned(self) -> Flag<'static> { + match self { + Flag::Custom(cow) => Flag::Custom(Cow::Owned(cow.into_owned())), + Flag::Seen => Flag::Seen, + Flag::Answered => Flag::Answered, + Flag::Flagged => Flag::Flagged, + Flag::Deleted => Flag::Deleted, + Flag::Draft => Flag::Draft, + Flag::Recent => Flag::Recent, + Flag::MayCreate => Flag::MayCreate, + } + } +} + impl<'a> std::fmt::Display for Flag<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { diff --git a/src/types/name.rs b/src/types/name.rs index 9f86f83..915cc93 100644 --- a/src/types/name.rs +++ b/src/types/name.rs @@ -104,6 +104,18 @@ impl NameAttribute<'static> { } } +impl<'a> NameAttribute<'a> { + fn into_owned(self) -> NameAttribute<'static> { + match self { + NameAttribute::NoInferiors => NameAttribute::NoInferiors, + NameAttribute::NoSelect => NameAttribute::NoSelect, + NameAttribute::Marked => NameAttribute::Marked, + NameAttribute::Unmarked => NameAttribute::Unmarked, + NameAttribute::Custom(cow) => NameAttribute::Custom(Cow::Owned(cow.into_owned())), + } + } +} + impl<'a> From for NameAttribute<'a> { fn from(s: String) -> Self { if let Some(f) = NameAttribute::system(&s) { @@ -155,4 +167,17 @@ impl<'a> Name<'a> { pub fn name(&self) -> &str { &*self.name } + + /// Get an owned version of this [`Name`]. + pub fn into_owned(self) -> Name<'static> { + Name { + attributes: self + .attributes + .into_iter() + .map(|av| av.into_owned()) + .collect(), + delimiter: self.delimiter.map(|cow| Cow::Owned(cow.into_owned())), + name: Cow::Owned(self.name.into_owned()), + } + } }