[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> {
fn to_as_uri(&self) -> Option<String> {
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(|| {
self.as_many().and_then(|props| {
props
.iter()
.next()
.and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string()))
})
self.as_many()
.and_then(|props| props.iter().next().and_then(|prop| prop.as_xsd_any_uri()))
})
.map(|uri| uri.to_string())
}
}