From 7e68da975ba2b6cd3ca002ed5751572ddcb15dd0 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Tue, 13 May 2025 00:08:03 +0200 Subject: [PATCH] Simplify from_user with `and_then` --- youmubot-osu/src/discord/mod.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index 4b9b578..70165c7 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -502,17 +502,13 @@ pub(crate) struct UserExtras { impl UserExtras { // Collect UserExtras from the given user. pub async fn from_user(env: &OsuEnv, user: &User, mode: Mode) -> Result { - let scores = { - match env - .client - .user_best(UserID::ID(user.id), |f| f.mode(mode)) - .await - .pls_ok() - { - Some(v) => v.get_all().await.pls_ok().unwrap_or_else(Vec::new), - None => Vec::new(), - } - }; + let scores = env + .client + .user_best(UserID::ID(user.id), |f| f.mode(mode)) + .and_then(|v| v.get_all()) + .await + .pls_ok() + .unwrap_or_else(Vec::new); let (length, age) = join!( calculate_weighted_map_length(&scores, &env.beatmaps, mode),