Implement OneOrMany<AnyBase>::to_as_uri()

This commit is contained in:
Kitaiti Makoto 2022-02-13 01:23:36 +09:00
parent 456df3e535
commit bb5157637d

View file

@ -1,6 +1,7 @@
use activitypub::{Activity, Link, Object};
use activitystreams::{
actor::{ApActor, Group, Person},
base::AnyBase,
iri_string::types::IriString,
markers::Activity as Activity07,
object::{ApObject, Article},
@ -438,6 +439,25 @@ impl AsAsStr for OneOrMany<&AnyString> {
}
}
pub trait ToAsUri {
fn to_as_uri(&self) -> Option<String>;
}
impl ToAsUri for OneOrMany<AnyBase> {
fn to_as_uri(&self) -> Option<String> {
if let Some(prop) = self.as_one() {
prop.as_xsd_any_uri().map(|uri| uri.to_string())
} else if let Some(prop) = self.as_many() {
prop.iter()
.next()
.and_then(|p| p.as_xsd_any_uri())
.map(|uri| uri.to_string())
} else {
None
}
}
}
#[cfg(test)]
mod tests {
use super::*;