From d3e11c78d7a0904f45a4cbab0f1cc741d43d2c2b Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 13 Feb 2022 01:31:15 +0900 Subject: [PATCH] [REFACTORING]Use method chain instead of if clauses --- plume-common/src/activity_pub/mod.rs | 20 ++++++++++---------- plume-models/src/users.rs | 6 +----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index b8853d1b..493980bc 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -445,16 +445,16 @@ pub trait ToAsUri { impl ToAsUri for OneOrMany { fn to_as_uri(&self) -> Option { - if let Some(prop) = self.as_one() { - prop.as_xsd_any_uri().map(|uri| uri.to_string()) - } else if let Some(prop) = self.as_many() { - prop.iter() - .next() - .and_then(|p| p.as_xsd_any_uri()) - .map(|uri| uri.to_string()) - } else { - None - } + self.as_one() + .and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string())) + .or_else(|| { + self.as_many().and_then(|props| { + props + .iter() + .next() + .and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string())) + }) + }) } } diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 5f1152be..33c3d2f4 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -1074,11 +1074,7 @@ impl FromId07 for User { ..NewUser::default() }; - let avatar_id = if let Some(icon) = acct.object_ref().icon() { - icon.to_as_uri() - } else { - None - }; + let avatar_id = acct.object_ref().icon().and_then(|icon| icon.to_as_uri()); let (ap_url, inst) = { let any_base = acct.into_any_base()?;