diff --git a/youmubot-cf/src/lib.rs b/youmubot-cf/src/lib.rs index 08f3f54..6331a2d 100644 --- a/youmubot-cf/src/lib.rs +++ b/youmubot-cf/src/lib.rs @@ -176,7 +176,7 @@ pub async fn ranks(ctx: &Context, m: &Message) -> CommandResult { let ranks = Arc::new(ranks); const ITEMS_PER_PAGE: usize = 10; - let total_pages = (ranks.len() + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE; + let total_pages = ranks.len().div_ceil(ITEMS_PER_PAGE); let last_updated = ranks.iter().map(|(_, cfu)| cfu.last_update).min().unwrap(); paginate_reply( @@ -308,7 +308,7 @@ pub(crate) async fn contest_rank_table( ranks: Vec<(Member, String, codeforces::RanklistRow)>, ) -> Result<()> { const ITEMS_PER_PAGE: usize = 10; - let total_pages = (ranks.len() + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE; + let total_pages = ranks.len().div_ceil(ITEMS_PER_PAGE); if ranks.is_empty() { reply_to diff --git a/youmubot-core/src/admin/ignore.rs b/youmubot-core/src/admin/ignore.rs index 379bf0e..52b9665 100644 --- a/youmubot-core/src/admin/ignore.rs +++ b/youmubot-core/src/admin/ignore.rs @@ -82,7 +82,7 @@ async fn list(ctx: CmdContext<'_, U>) -> Result<()> { }) .collect::>() .join("\n"); - let users = if users == "" { + let users = if users.is_empty() { "No one is being ignored!" } else { &users[..] @@ -118,10 +118,7 @@ impl IgnoredUsers { Ok(Self { list: Arc::new(mp) }) } - pub fn query<'a>( - &'a self, - id: UserId, - ) -> Option + 'a> { + pub fn query(&self, id: UserId) -> Option + '_> { self.list.get(&id) } diff --git a/youmubot-core/src/community/roles.rs b/youmubot-core/src/community/roles.rs index eaaf9d8..84d0be1 100644 --- a/youmubot-core/src/community/roles.rs +++ b/youmubot-core/src/community/roles.rs @@ -40,7 +40,7 @@ async fn list(ctx: &Context, m: &Message, _: Args) -> CommandResult { .filter_map(|(_, role)| roles.get(&role.id).cloned().map(|r| (r, role.description))) .collect(); const ROLES_PER_PAGE: usize = 8; - let pages = (roles.len() + ROLES_PER_PAGE - 1) / ROLES_PER_PAGE; + let pages = roles.len().div_ceil(ROLES_PER_PAGE); paginate_reply( paginate_from_fn(|page, btns| { diff --git a/youmubot-core/src/fun/names.rs b/youmubot-core/src/fun/names.rs index fd30491..c23596c 100644 --- a/youmubot-core/src/fun/names.rs +++ b/youmubot-core/src/fun/names.rs @@ -473,7 +473,7 @@ const FIRST_NAMES: [&str; 440] = [ "Yusuke", ]; -const LAST_NAMES: [&str; 1051] = [ +static LAST_NAMES: [&str; 1051] = [ // A Surnames "Abe", "Abukara", diff --git a/youmubot-core/src/lib.rs b/youmubot-core/src/lib.rs index d2470ae..3cf4d15 100644 --- a/youmubot-core/src/lib.rs +++ b/youmubot-core/src/lib.rs @@ -45,8 +45,8 @@ impl + Send + Sync> HasCoreEnv for T { pub async fn setup(path: &std::path::Path, data: &mut TypeMap, prelude: Env) -> Result { db::load_role_list( &mut *data, - &path.join("roles_v2.yaml"), - &path.join("roles.yaml"), + path.join("roles_v2.yaml"), + path.join("roles.yaml"), )?; // Start reaction handlers diff --git a/youmubot-db/src/lib.rs b/youmubot-db/src/lib.rs index 34f09a3..dc7ee24 100644 --- a/youmubot-db/src/lib.rs +++ b/youmubot-db/src/lib.rs @@ -64,7 +64,7 @@ where } } -impl<'a, T> DBWriteGuard<'a, T> +impl DBWriteGuard<'_, T> where T: Send + Sync + Clone + std::fmt::Debug + Serialize + DeserializeOwned, { @@ -79,7 +79,7 @@ where } } -impl<'a, T> Drop for DBWriteGuard<'a, T> +impl Drop for DBWriteGuard<'_, T> where T: Send + Sync + Clone + std::fmt::Debug + Serialize + DeserializeOwned, { diff --git a/youmubot-osu/src/discord/announcer.rs b/youmubot-osu/src/discord/announcer.rs index 1a0277c..da30934 100644 --- a/youmubot-osu/src/discord/announcer.rs +++ b/youmubot-osu/src/discord/announcer.rs @@ -291,7 +291,7 @@ impl<'a> CollectedScore<'a> { } } -impl<'a> CollectedScore<'a> { +impl CollectedScore<'_> { async fn send_message( self, ctx: impl CacheHttp, diff --git a/youmubot-osu/src/discord/commands.rs b/youmubot-osu/src/discord/commands.rs index 82a829c..f38f935 100644 --- a/youmubot-osu/src/discord/commands.rs +++ b/youmubot-osu/src/discord/commands.rs @@ -186,7 +186,6 @@ pub async fn save( ctx.defer().await?; let (u, mode, score, beatmap, info) = find_save_requirements(env, username).await?; let reply = ctx - .clone() .send( CreateReply::default() .content(save_request_message(&u.username, score.beatmap_id, mode)) @@ -197,10 +196,10 @@ pub async fn save( ]), ) .await?; - let mut p = (reply, ctx.clone()); + let mut p = (reply, ctx); match handle_save_respond( ctx.serenity_context(), - &env, + env, ctx.author().id, &mut p, &beatmap, @@ -212,7 +211,7 @@ pub async fn save( Ok(_) => (), Err(e) => { p.0.delete(ctx).await?; - return Err(e.into()); + return Err(e); } }; @@ -235,8 +234,8 @@ pub async fn forcesave( else { return Err(Error::msg("osu! user not found")); }; - add_user(discord_name.id, &u, &env).await?; - let ex = UserExtras::from_user(&env, &u, u.preferred_mode).await?; + add_user(discord_name.id, &u, env).await?; + let ex = UserExtras::from_user(env, &u, u.preferred_mode).await?; ctx.send( CreateReply::default() .content( @@ -289,8 +288,7 @@ async fn handle_listing( user.mention() )) .embed({ - let mut b = - transform(nth + 1, score_embed(&play, &beatmap, &content, user)); + let mut b = transform(nth + 1, score_embed(play, &beatmap, &content, user)); if let Some(rank) = play.global_rank { b = b.world_record(rank as u16); } @@ -301,15 +299,15 @@ async fn handle_listing( .await?; // Save the beatmap... - cache::save_beatmap(&env, ctx.channel_id(), &beatmap).await?; + cache::save_beatmap(env, ctx.channel_id(), &beatmap).await?; } Nth::All => { let header = format!("Here are the {} plays by {}!", listing_kind, user.mention()); - let reply = ctx.clone().reply(&header).await?; + let reply = ctx.reply(&header).await?; style .display_scores( plays, - ctx.clone().serenity_context(), + ctx.serenity_context(), ctx.guild_id(), (reply, ctx).with_header(header), ) @@ -380,11 +378,10 @@ async fn beatmap( EmbedType::Beatmapset(vec, _) => { let b0 = &vec[0]; let msg = ctx - .clone() .reply(format!("Information for {}", b0.beatmapset_mention())) .await?; display_beatmapset( - ctx.clone().serenity_context(), + ctx.serenity_context(), vec, mode, mods, @@ -480,7 +477,7 @@ async fn check( args.user.mention(), display ); - let msg = ctx.clone().reply(&header).await?; + let msg = ctx.reply(&header).await?; let style = style.unwrap_or(if scores.len() <= 5 { ScoreListStyle::Grid @@ -491,7 +488,7 @@ async fn check( style .display_scores( scores, - ctx.clone().serenity_context(), + ctx.serenity_context(), ctx.guild_id(), (msg, ctx).with_header(header), ) @@ -512,7 +509,7 @@ async fn ranks( let guild = ctx.partial_guild().await.unwrap(); ctx.defer().await?; server_rank::do_server_ranks( - ctx.clone().serenity_context(), + ctx.serenity_context(), env, &guild, mode, @@ -551,7 +548,7 @@ async fn leaderboard( let scoreboard_msg = embed.mention(); let (mut scores, show_diff) = get_leaderboard_from_embed( ctx.serenity_context(), - &env, + env, embed, None, unranked.unwrap_or(true), diff --git a/youmubot-osu/src/discord/db.rs b/youmubot-osu/src/discord/db.rs index eaa5501..9496c53 100644 --- a/youmubot-osu/src/discord/db.rs +++ b/youmubot-osu/src/discord/db.rs @@ -176,7 +176,7 @@ impl From for OsuUser { impl From for crate::models::UserHeader { fn from(value: OsuUser) -> Self { Self { - id: value.id as u64, + id: value.id, username: value.username.to_string(), } } diff --git a/youmubot-osu/src/discord/display.rs b/youmubot-osu/src/discord/display.rs index a9eee4e..088599a 100644 --- a/youmubot-osu/src/discord/display.rs +++ b/youmubot-osu/src/discord/display.rs @@ -138,7 +138,7 @@ mod scores { .await? .ok_or_else(|| Error::msg("user not found"))?; - save_beatmap(&env, self.channel_id, &bm).await?; + save_beatmap(env, self.channel_id, &bm).await?; Ok(Some( CreateReply::default() .embed({ @@ -479,7 +479,7 @@ mod beatmapset { .oppai .get_beatmap(b.beatmap_id) .await - .map(move |v| v.get_possible_pp_with(b.mode.with_override(self.mode), &mods)) + .map(move |v| v.get_possible_pp_with(b.mode.with_override(self.mode), mods)) } } diff --git a/youmubot-osu/src/discord/embeds.rs b/youmubot-osu/src/discord/embeds.rs index bc0c4cd..571e86c 100644 --- a/youmubot-osu/src/discord/embeds.rs +++ b/youmubot-osu/src/discord/embeds.rs @@ -269,7 +269,7 @@ pub(crate) struct ScoreEmbedBuilder<'a> { footer: Option, } -impl<'a> ScoreEmbedBuilder<'a> { +impl ScoreEmbedBuilder<'_> { pub fn top_record(mut self, rank: u8) -> Self { self.top_record = Some(rank); self @@ -304,7 +304,7 @@ pub(crate) fn score_embed<'a>( } } -impl<'a> ScoreEmbedBuilder<'a> { +impl ScoreEmbedBuilder<'_> { #[allow(clippy::many_single_char_names)] pub fn build(mut self) -> CreateEmbed { let mode = self.bm.mode(); @@ -471,7 +471,7 @@ pub(crate) struct FakeScore<'a> { pub max_combo: Option, } -impl<'a> FakeScore<'a> { +impl FakeScore<'_> { fn score_origin(&self, attrs: &OsuPerformanceAttributes) -> OsuScoreOrigin { if !self.mods.is_lazer { OsuScoreOrigin::Stable diff --git a/youmubot-osu/src/discord/hook.rs b/youmubot-osu/src/discord/hook.rs index bde485f..3a0d568 100644 --- a/youmubot-osu/src/discord/hook.rs +++ b/youmubot-osu/src/discord/hook.rs @@ -135,7 +135,7 @@ pub fn dot_osu_hook<'a>( .collect::>() .await; - const ARCHIVE_EXTS: [&'static str; 2] = [".osz", ".olz"]; + const ARCHIVE_EXTS: [&str; 2] = [".osz", ".olz"]; let osz_embeds = msg .attachments .iter() diff --git a/youmubot-osu/src/discord/interaction.rs b/youmubot-osu/src/discord/interaction.rs index b1900db..d2fc8c6 100644 --- a/youmubot-osu/src/discord/interaction.rs +++ b/youmubot-osu/src/discord/interaction.rs @@ -109,7 +109,7 @@ pub fn handle_check_button<'a>( let guild_id = comp.guild_id; ScoreListStyle::Grid - .display_scores(scores, &ctx, guild_id, (comp, ctx).with_header(header)) + .display_scores(scores, ctx, guild_id, (comp, ctx).with_header(header)) .await .pls_ok(); Ok(()) @@ -209,7 +209,7 @@ pub fn handle_simulate_button<'a>( let Some(query) = comp .quick_modal( - &ctx, + ctx, CreateQuickModal::new(format!( "Simulate Score on beatmap `{}`", b.short_link(None, Mods::NOMOD) @@ -263,7 +263,7 @@ async fn handle_simluate_query( let (mods, max_combo, c100, c50, cmiss) = (&inputs[0], &inputs[1], &inputs[2], &inputs[3], &inputs[4]); let mods = UnparsedMods::from_str(mods) - .map_err(|v| Error::msg(v))? + .map_err(Error::msg)? .to_mods(mode)?; let info = content.get_info_with(mode, &mods); let max_combo = max_combo.parse::().ok(); @@ -351,7 +351,7 @@ async fn handle_last_req( &ctx, serenity::all::CreateInteractionResponseFollowup::new() .content(content_type) - .embed(beatmap_embed(&*b, m.unwrap_or(b.mode), &mods, &info)) + .embed(beatmap_embed(&b, m.unwrap_or(b.mode), &mods, &info)) .components(vec![beatmap_components(m.unwrap_or(b.mode), comp.guild_id)]), ) .await?; diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index 70165c7..34bd53f 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -361,7 +361,7 @@ pub(crate) async fn handle_save_respond( .is_some_and(|s| s.beatmap_id == map_id)) } let msg_id = reply.get_message().await?.id; - let recv = InteractionCollector::create(&ctx, msg_id).await?; + let recv = InteractionCollector::create(ctx, msg_id).await?; let timeout = std::time::Duration::from_secs(300) + beatmap.difficulty.total_length; let completed = loop { let Some(reaction) = recv.next(timeout).await else { @@ -385,7 +385,7 @@ pub(crate) async fn handle_save_respond( return Ok(()); } - add_user(sender, &user, &env).await?; + add_user(sender, &user, env).await?; let ex = UserExtras::from_user(env, &user, mode).await?; reply .apply_edit( @@ -450,7 +450,7 @@ async fn add_user(target: serenity::model::id::UserId, user: &User, env: &OsuEnv let modes = [Mode::Std, Mode::Taiko, Mode::Catch, Mode::Mania] .into_iter() .map(|mode| { - let mode = mode.clone(); + let mode = mode; async move { let pp = async { env.client @@ -790,7 +790,7 @@ pub async fn pins(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult &ctx, CreateMessage::new() .content("Here is the play that you requested".to_string()) - .embed(score_embed(&play, &beatmap_mode, &content, user).build()) + .embed(score_embed(play, &beatmap_mode, &content, user).build()) .components(vec![score_components(msg.guild_id)]) .reference_message(msg), ) @@ -908,13 +908,11 @@ pub(crate) async fn load_beatmap( None => load_beatmap_from_channel(env, channel_id).await, }; - if req == LoadRequest::Beatmapset { - if embed.is_none() { - if let Some(EmbedType::Beatmap(b, mode, _, _)) = fallback { - return EmbedType::from_beatmapset_id(env, b.beatmapset_id, mode) - .await - .ok(); - } + if req == LoadRequest::Beatmapset && embed.is_none() { + if let Some(EmbedType::Beatmap(b, mode, _, _)) = fallback { + return EmbedType::from_beatmapset_id(env, b.beatmapset_id, mode) + .await + .ok(); } } embed @@ -1052,7 +1050,7 @@ pub(crate) async fn do_check( .scores(b.beatmap_id, |f| f.user(UserID::ID(user.id)).mode(m)) .and_then(|v| v.get_all()) .map_ok(move |mut v| { - v.retain(|s| mods.as_ref().is_none_or(|m| s.mods.contains(&m))); + v.retain(|s| mods.as_ref().is_none_or(|m| s.mods.contains(m))); v }) .await @@ -1060,7 +1058,7 @@ pub(crate) async fn do_check( let mut scores = match embed { EmbedType::Beatmap(beatmap, mode, _, _) => { - fetch_for_beatmap(env, &**beatmap, *mode, &mods, user).await? + fetch_for_beatmap(env, beatmap, *mode, &mods, user).await? } EmbedType::Beatmapset(vec, mode) => vec .iter() @@ -1118,7 +1116,7 @@ pub async fn top(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult user.mention() )) .embed( - score_embed(&play, &beatmap, &content, user) + score_embed(play, &beatmap, &content, user) .top_record(nth + 1) .build(), ) diff --git a/youmubot-osu/src/discord/server_rank.rs b/youmubot-osu/src/discord/server_rank.rs index 476e1e9..551ea4c 100644 --- a/youmubot-osu/src/discord/server_rank.rs +++ b/youmubot-osu/src/discord/server_rank.rs @@ -234,7 +234,7 @@ where let users = Arc::new(users); let last_update = last_update.unwrap(); let total_len = users.len(); - let total_pages = (total_len + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE; + let total_pages = total_len.div_ceil(ITEMS_PER_PAGE); paginate_with_first_message( paginate_from_fn(move |page: u8, btns| { let header = header.clone(); @@ -404,7 +404,7 @@ pub async fn show_leaderboard(ctx: &Context, msg: &Message, mut args: Args) -> C let header = format!( "Here are the top scores of **{}** on {}", - guild.name(&ctx).unwrap(), + guild.name(ctx).unwrap(), scoreboard_msg, ); let has_lazer_score = scores.iter().any(|v| v.score.mods.is_lazer); @@ -587,7 +587,7 @@ pub async fn get_leaderboard_from_embed( let iter = std::iter::once(*map); let scores = get_leaderboard( ctx, - &env, + env, iter, mode_override.or(mode), show_unranked, @@ -603,7 +603,7 @@ pub async fn get_leaderboard_from_embed( ( get_leaderboard( ctx, - &env, + env, maps, mode_override.or(mode), show_unranked, @@ -689,7 +689,7 @@ pub(crate) fn rankings_to_table( } else { beatmap.difficulty_name.clone() }; - format!("[{:.2}*] {} {}", star, trimmed_diff, score.mods.to_string()) + format!("[{:.2}*] {} {}", star, trimmed_diff, score.mods) } else { score.mods.to_string() }, @@ -716,7 +716,7 @@ pub async fn display_rankings_table( ) -> Result<()> { const ITEMS_PER_PAGE: usize = 5; let total_len = scores.len(); - let total_pages = (total_len + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE; + let total_pages = total_len.div_ceil(ITEMS_PER_PAGE); let header = to.content.clone(); paginate_with_first_message( diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index 27bd6cc..f28d5b0 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -125,9 +125,9 @@ impl Difficulty { if let Some(ratio) = mods.inner.clock_rate() { if ratio != 1.0 { - diff.apply_length_by_ratio(1.0 / ratio as f64); - diff.apply_ar_by_time_ratio(1.0 / ratio as f64); - diff.apply_od_by_time_ratio(1.0 / ratio as f64); + diff.apply_length_by_ratio(1.0 / ratio); + diff.apply_ar_by_time_ratio(1.0 / ratio); + diff.apply_od_by_time_ratio(1.0 / ratio); } } @@ -587,7 +587,7 @@ pub struct User { } impl User { - pub fn mention<'a>(&'a self) -> impl Display + 'a { + pub fn mention(&self) -> impl Display + '_ { UserHeaderLink(&self.username, self.id) } @@ -603,14 +603,14 @@ impl User { #[derive(Debug, Clone)] struct UserHeaderLink<'a>(&'a String, u64); -impl<'a> Display for UserHeaderLink<'a> { +impl Display for UserHeaderLink<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "[{}]()", self.0, self.1) } } impl UserHeader { - pub fn mention<'a>(&'a self) -> impl Display + 'a { + pub fn mention(&self) -> impl Display + '_ { UserHeaderLink(&self.username, self.id) } diff --git a/youmubot-osu/src/models/rosu.rs b/youmubot-osu/src/models/rosu.rs index 0c9cb98..7df21d5 100644 --- a/youmubot-osu/src/models/rosu.rs +++ b/youmubot-osu/src/models/rosu.rs @@ -116,7 +116,7 @@ impl From for Score { s.score as u64 } else { s.classic_score - } as u64; + }; Self { id: Some(s.id), user_id: s.user_id as u64, diff --git a/youmubot-osu/src/request/mod.rs b/youmubot-osu/src/request/mod.rs index a13eee0..eb13d29 100644 --- a/youmubot-osu/src/request/mod.rs +++ b/youmubot-osu/src/request/mod.rs @@ -215,7 +215,7 @@ pub mod builders { match &self.mods { Some(mods) => r.await.map(|mut ss| { ss.retain(|s| { - Mods::from_gamemods(s.mods.clone(), s.set_on_lazer).contains(&mods) + Mods::from_gamemods(s.mods.clone(), s.set_on_lazer).contains(mods) }); ss }), @@ -225,7 +225,7 @@ pub mod builders { None => { let mut r = osu.rosu.beatmap_scores(self.beatmap_id as u32).global(); if let Some(mode) = &self.mode { - r = r.mode(mode.clone().into()); + r = r.mode((*mode).into()); } if let Some(mods) = &self.mods { r = r.mods(GameModsIntermode::from(mods.inner.clone())); @@ -241,7 +241,7 @@ pub mod builders { pub(crate) async fn build(self, osu: &OsuClient) -> Result { // user queries always return all scores, so no need to consider offset. // otherwise, it's not working anyway... - Ok(self.fetch_scores(osu, 0).await?) + self.fetch_scores(osu, 0).await } } diff --git a/youmubot-osu/src/request/scores.rs b/youmubot-osu/src/request/scores.rs index 1ef3171..f113009 100644 --- a/youmubot-osu/src/request/scores.rs +++ b/youmubot-osu/src/request/scores.rs @@ -106,7 +106,7 @@ impl Scores for Vec { } async fn find bool + Send>(&mut self, mut f: F) -> Result> { - Ok(self.iter().find(|v| f(*v))) + Ok(self.iter().find(|v| f(v))) } } @@ -155,7 +155,7 @@ impl Scores for ScoresFetcher { /// Get the index-th score. async fn get(&mut self, index: usize) -> Result> { - Ok(self.get_range(index..(index + 1)).await?.get(0)) + Ok(self.get_range(index..(index + 1)).await?.first()) } /// Get all scores. diff --git a/youmubot-prelude/src/interaction_collector.rs b/youmubot-prelude/src/interaction_collector.rs index 09007ad..4faefc6 100644 --- a/youmubot-prelude/src/interaction_collector.rs +++ b/youmubot-prelude/src/interaction_collector.rs @@ -42,6 +42,12 @@ impl Drop for InteractionCollectorGuard { } } +impl Default for InteractionCollector { + fn default() -> Self { + Self::new() + } +} + impl InteractionCollector { pub fn new() -> Self { Self { @@ -51,7 +57,7 @@ impl InteractionCollector { /// Create a new collector, returning a receiver. pub fn create_collector(&self, msg: MessageId) -> InteractionCollectorGuard { let (send, recv) = flume::unbounded(); - self.channels.insert(msg.clone(), send); + self.channels.insert(msg, send); InteractionCollectorGuard { msg_id: msg, ch: recv, diff --git a/youmubot-prelude/src/pagination.rs b/youmubot-prelude/src/pagination.rs index eea9b6f..434df6c 100644 --- a/youmubot-prelude/src/pagination.rs +++ b/youmubot-prelude/src/pagination.rs @@ -43,7 +43,7 @@ impl CanEdit for WithHeaders { } } -impl<'a> CanEdit for (Message, &'a Context) { +impl CanEdit for (Message, &Context) { async fn get_message(&self) -> Result { Ok(self.0.clone()) } @@ -56,7 +56,7 @@ impl<'a> CanEdit for (Message, &'a Context) { } } -impl<'a, 'b> CanEdit for (&'a ComponentInteraction, &'b Context) { +impl CanEdit for (&ComponentInteraction, &Context) { async fn get_message(&self) -> Result { Ok(self.0.get_response(&self.1.http).await?) } @@ -72,7 +72,7 @@ impl<'a, 'b> CanEdit for (&'a ComponentInteraction, &'b Context) { } } -impl<'a, 'e, Env: Send + Sync> CanEdit for (ReplyHandle<'a>, CmdContext<'e, Env>) { +impl CanEdit for (ReplyHandle<'_>, CmdContext<'_, Env>) { async fn get_message(&self) -> Result { Ok(self.0.message().await?.into_owned()) } @@ -326,13 +326,7 @@ pub async fn handle_pagination_reaction( let new_page = match reaction { PREV | FAST_PREV if page == 0 => return Ok(page), PREV => page - 1, - FAST_PREV => { - if page < fast { - 0 - } else { - page - fast - } - } + FAST_PREV => page.saturating_sub(fast), NEXT if pages.filter(|&pages| page as usize + 1 >= pages).is_some() => return Ok(page), NEXT => page + 1, FAST_NEXT => (pages.unwrap() as u8 - 1).min(page + fast), diff --git a/youmubot-prelude/src/ratelimit.rs b/youmubot-prelude/src/ratelimit.rs index 122f96e..6354d8e 100644 --- a/youmubot-prelude/src/ratelimit.rs +++ b/youmubot-prelude/src/ratelimit.rs @@ -50,14 +50,14 @@ impl Ratelimit { } } -impl<'a, T> Deref for RatelimitGuard<'a, T> { +impl Deref for RatelimitGuard<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { self.inner } } -impl<'a, T> Drop for RatelimitGuard<'a, T> { +impl Drop for RatelimitGuard<'_, T> { fn drop(&mut self) { let send = self.send.clone(); let wait_time = *self.wait_time;