mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-26 21:41:04 +00:00
Implement OneOrMany<AnyBase>::to_as_uri()
This commit is contained in:
parent
456df3e535
commit
bb5157637d
1 changed files with 20 additions and 0 deletions
|
@ -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::*;
|
||||
|
|
Loading…
Reference in a new issue