Add into_owned() for Fetch, Flag, and Name.
This commit is contained in:
parent
fadb28a32b
commit
54bca3eddb
3 changed files with 52 additions and 0 deletions
|
|
@ -213,4 +213,15 @@ impl<'a> Fetch<'a> {
|
||||||
_ => None,
|
_ => 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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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> {
|
impl<'a> std::fmt::Display for Flag<'a> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
||||||
|
|
@ -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<String> for NameAttribute<'a> {
|
impl<'a> From<String> for NameAttribute<'a> {
|
||||||
fn from(s: String) -> Self {
|
fn from(s: String) -> Self {
|
||||||
if let Some(f) = NameAttribute::system(&s) {
|
if let Some(f) = NameAttribute::system(&s) {
|
||||||
|
|
@ -155,4 +167,17 @@ impl<'a> Name<'a> {
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&*self.name
|
&*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()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue