mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-25 05:11:03 +00:00
Add to_owned to OneOrMany<&'a AnyString>
This commit is contained in:
parent
88470a3199
commit
2ae512e3f5
2 changed files with 20 additions and 0 deletions
|
@ -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>`
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue