mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 17:20:49 +00:00
Simplify from_user with and_then
This commit is contained in:
parent
dde78b32d3
commit
7e68da975b
1 changed files with 7 additions and 11 deletions
|
@ -502,17 +502,13 @@ pub(crate) struct UserExtras {
|
||||||
impl UserExtras {
|
impl UserExtras {
|
||||||
// Collect UserExtras from the given user.
|
// Collect UserExtras from the given user.
|
||||||
pub async fn from_user(env: &OsuEnv, user: &User, mode: Mode) -> Result<Self> {
|
pub async fn from_user(env: &OsuEnv, user: &User, mode: Mode) -> Result<Self> {
|
||||||
let scores = {
|
let scores = env
|
||||||
match env
|
.client
|
||||||
.client
|
.user_best(UserID::ID(user.id), |f| f.mode(mode))
|
||||||
.user_best(UserID::ID(user.id), |f| f.mode(mode))
|
.and_then(|v| v.get_all())
|
||||||
.await
|
.await
|
||||||
.pls_ok()
|
.pls_ok()
|
||||||
{
|
.unwrap_or_else(Vec::new);
|
||||||
Some(v) => v.get_all().await.pls_ok().unwrap_or_else(Vec::new),
|
|
||||||
None => Vec::new(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let (length, age) = join!(
|
let (length, age) = join!(
|
||||||
calculate_weighted_map_length(&scores, &env.beatmaps, mode),
|
calculate_weighted_map_length(&scores, &env.beatmaps, mode),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue