Skip to content

Commit 54bca3e

Browse files
committed
Add into_owned() for Fetch, Flag, and Name.
1 parent fadb28a commit 54bca3e

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/types/fetch.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,15 @@ impl<'a> Fetch<'a> {
213213
_ => None,
214214
})
215215
}
216+
217+
/// Get an owned copy of the [`Fetch`].
218+
pub fn into_owned(self) -> Fetch<'static> {
219+
Fetch {
220+
message: self.message,
221+
uid: self.uid,
222+
size: self.size,
223+
fetch: self.fetch.into_iter().map(|av| av.into_owned()).collect(),
224+
flags: self.flags.clone(),
225+
}
226+
}
216227
}

src/types/flag.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ impl Flag<'static> {
7272
}
7373
}
7474

75+
impl<'a> Flag<'a> {
76+
/// Get an owned version of the [`Flag`].
77+
pub fn into_owned(self) -> Flag<'static> {
78+
match self {
79+
Flag::Custom(cow) => Flag::Custom(Cow::Owned(cow.into_owned())),
80+
Flag::Seen => Flag::Seen,
81+
Flag::Answered => Flag::Answered,
82+
Flag::Flagged => Flag::Flagged,
83+
Flag::Deleted => Flag::Deleted,
84+
Flag::Draft => Flag::Draft,
85+
Flag::Recent => Flag::Recent,
86+
Flag::MayCreate => Flag::MayCreate,
87+
}
88+
}
89+
}
90+
7591
impl<'a> std::fmt::Display for Flag<'a> {
7692
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7793
match *self {

src/types/name.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ impl NameAttribute<'static> {
104104
}
105105
}
106106

107+
impl<'a> NameAttribute<'a> {
108+
fn into_owned(self) -> NameAttribute<'static> {
109+
match self {
110+
NameAttribute::NoInferiors => NameAttribute::NoInferiors,
111+
NameAttribute::NoSelect => NameAttribute::NoSelect,
112+
NameAttribute::Marked => NameAttribute::Marked,
113+
NameAttribute::Unmarked => NameAttribute::Unmarked,
114+
NameAttribute::Custom(cow) => NameAttribute::Custom(Cow::Owned(cow.into_owned())),
115+
}
116+
}
117+
}
118+
107119
impl<'a> From<String> for NameAttribute<'a> {
108120
fn from(s: String) -> Self {
109121
if let Some(f) = NameAttribute::system(&s) {
@@ -155,4 +167,17 @@ impl<'a> Name<'a> {
155167
pub fn name(&self) -> &str {
156168
&*self.name
157169
}
170+
171+
/// Get an owned version of this [`Name`].
172+
pub fn into_owned(self) -> Name<'static> {
173+
Name {
174+
attributes: self
175+
.attributes
176+
.into_iter()
177+
.map(|av| av.into_owned())
178+
.collect(),
179+
delimiter: self.delimiter.map(|cow| Cow::Owned(cow.into_owned())),
180+
name: Cow::Owned(self.name.into_owned()),
181+
}
182+
}
158183
}

0 commit comments

Comments
 (0)