mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 19:41:03 +00:00
Implement OneOrMany<&AnyString>::to_as_string()
This commit is contained in:
parent
e407d58ee9
commit
a80a95d471
1 changed files with 22 additions and 0 deletions
|
@ -4,6 +4,7 @@ use activitystreams::{
|
|||
iri_string::types::IriString,
|
||||
markers::Activity as Activity07,
|
||||
object::{ApObject, Article},
|
||||
primitives::{AnyString, OneOrMany},
|
||||
unparsed::UnparsedMutExt,
|
||||
};
|
||||
use activitystreams_ext::{Ext1, UnparsedExtension};
|
||||
|
@ -407,6 +408,27 @@ where
|
|||
|
||||
pub type LicensedArticle = Ext1<ApObject<Article>, Licensed07>;
|
||||
|
||||
pub trait ToAsString {
|
||||
fn to_as_string(&self) -> Option<String>;
|
||||
}
|
||||
|
||||
impl ToAsString for OneOrMany<&AnyString> {
|
||||
fn to_as_string(&self) -> Option<String> {
|
||||
if let Some(prop) = self.as_one() {
|
||||
prop.as_xsd_string()
|
||||
.or_else(|| prop.as_rdf_lang_string().map(|ls| ls.value.as_str()))
|
||||
} else if let Some(props) = self.as_many() {
|
||||
props.iter().next().and_then(|prop| {
|
||||
prop.as_xsd_string()
|
||||
.or_else(|| prop.as_rdf_lang_string().map(|ls| ls.value.as_str()))
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.map(|s| s.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue