From f0112850fa94b9c6e3d713403936c68636b3a918 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 13 Feb 2022 01:15:23 +0900 Subject: [PATCH] Implement OneOrMany<&AnyString>::as_as_str() --- plume-common/src/activity_pub/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index fc9098b2..f4e681ef 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -435,6 +435,15 @@ impl AsAsStr for &AnyString { } } +impl AsAsStr for OneOrMany<&AnyString> { + fn as_as_str(&self) -> Option<&str> { + self.as_one().and_then(|prop| prop.as_as_str()).or_else(|| { + self.as_many() + .and_then(|props| props.iter().next().and_then(|prop| prop.as_as_str())) + }) + } +} + #[cfg(test)] mod tests { use super::*;