Add to_owned to OneOrMany<&'a AnyString>

This commit is contained in:
asonix 2021-03-09 19:49:04 -06:00
parent 88470a3199
commit 2ae512e3f5
2 changed files with 20 additions and 0 deletions

View file

@ -1,4 +1,5 @@
# Unreleased
- Add `to_owned` to `OneOrMany<&'a AnyString>`
# 0.7.0-alpha.11
- Update summary and content to return `OneOrMany<&'a AnyString>`

View file

@ -345,6 +345,25 @@ impl OneOrMany<&AnyString> {
self.as_one()
.and_then(|any_string| any_string.as_rdf_lang_string())
}
/// Create and owned clone of the OneOrMany<AnyString>
///
/// ```rust
/// # use activitystreams::primitives::{OneOrMany, AnyString};
/// # let string = OneOrMany::<AnyString>::from_xsd_string("hey");
///
/// let borrowed_string: OneOrMany<&AnyString> = string.as_ref();
///
/// let owned_one_or_many: OneOrMany<AnyString> = borrowed_string.to_owned();
/// ```
pub fn to_owned(self) -> OneOrMany<AnyString> {
match self.0 {
Either::Left(one_ref) => OneOrMany(Either::Left(one_ref.to_owned())),
Either::Right(many_ref) => {
OneOrMany(Either::Right(many_ref.into_iter().cloned().collect()))
}
}
}
}
impl From<&str> for AnyString {