Use OneOrMany<&AnyString>::as_as_str()

This commit is contained in:
Kitaiti Makoto 2022-02-13 01:15:39 +09:00
parent f0112850fa
commit 456df3e535

View file

@ -414,13 +414,7 @@ pub trait ToAsString {
impl ToAsString for OneOrMany<&AnyString> { impl ToAsString for OneOrMany<&AnyString> {
fn to_as_string(&self) -> Option<String> { fn to_as_string(&self) -> Option<String> {
self.as_one() self.as_as_str().map(|s| s.to_string())
.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()))
})
.map(|s| s.to_string())
} }
} }