[REFACTORING]Reduce duplicated closure

This commit is contained in:
Kitaiti Makoto 2022-02-13 01:33:04 +09:00
parent d3e11c78d7
commit c1b9ebdae6

View File

@ -446,15 +446,12 @@ pub trait ToAsUri {
impl ToAsUri for OneOrMany<AnyBase> { impl ToAsUri for OneOrMany<AnyBase> {
fn to_as_uri(&self) -> Option<String> { fn to_as_uri(&self) -> Option<String> {
self.as_one() self.as_one()
.and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string())) .and_then(|prop| prop.as_xsd_any_uri())
.or_else(|| { .or_else(|| {
self.as_many().and_then(|props| { self.as_many()
props .and_then(|props| props.iter().next().and_then(|prop| prop.as_xsd_any_uri()))
.iter()
.next()
.and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string()))
})
}) })
.map(|uri| uri.to_string())
} }
} }