[REFACTORING]Use method chain instead of if clauses

This commit is contained in:
Kitaiti Makoto 2022-02-13 01:31:15 +09:00
parent 4ccfec8019
commit d3e11c78d7
2 changed files with 11 additions and 15 deletions

View File

@ -445,16 +445,16 @@ 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> {
if let Some(prop) = self.as_one() { self.as_one()
prop.as_xsd_any_uri().map(|uri| uri.to_string()) .and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string()))
} else if let Some(prop) = self.as_many() { .or_else(|| {
prop.iter() self.as_many().and_then(|props| {
props
.iter()
.next() .next()
.and_then(|p| p.as_xsd_any_uri()) .and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string()))
.map(|uri| uri.to_string()) })
} else { })
None
}
} }
} }

View File

@ -1074,11 +1074,7 @@ impl FromId07<DbConn> for User {
..NewUser::default() ..NewUser::default()
}; };
let avatar_id = if let Some(icon) = acct.object_ref().icon() { let avatar_id = acct.object_ref().icon().and_then(|icon| icon.to_as_uri());
icon.to_as_uri()
} else {
None
};
let (ap_url, inst) = { let (ap_url, inst) = {
let any_base = acct.into_any_base()?; let any_base = acct.into_any_base()?;