Skip to content

Commit ce2822b

Browse files
committed
🗑️ chore: fix deprecated warnings
1 parent eb7f5f8 commit ce2822b

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

src/assets/idiom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rand::{seq::IteratorRandom, thread_rng};
1+
use rand::{rng, seq::IteratorRandom};
22
use serde::{Deserialize, Serialize};
33
use std::{collections::HashMap, sync::LazyLock};
44

@@ -41,7 +41,7 @@ static IDIOM_MAP: LazyLock<HashMap<String, &'static Idiom>> = LazyLock::new(|| {
4141
});
4242

4343
pub fn random_idiom() -> &'static Idiom {
44-
IDIOMS.iter().choose(&mut thread_rng()).unwrap()
44+
IDIOMS.iter().choose(&mut rng()).unwrap()
4545
}
4646

4747
pub fn get_idiom(word: &str) -> Option<&'static Idiom> {

src/assets/tarot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rand::{random, seq::index, thread_rng};
1+
use rand::{random, seq::index, rng};
22
use std::fmt;
33

44
pub struct MajorArcana {
@@ -27,7 +27,7 @@ impl fmt::Display for TarotChoosen {
2727

2828
pub fn n_random_majors(n: usize) -> Vec<TarotChoosen> {
2929
assert!(n <= 22);
30-
index::sample(&mut thread_rng(), 21, n)
30+
index::sample(&mut rng(), 21, n)
3131
.into_iter()
3232
.map(|id| {
3333
let rev: bool = random();

src/mods/answer_book.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn on_bad_answer_message(ctx: &mut Context, _message: &Message) -> Consumption {
2929
let ctx = ctx.task();
3030
async move {
3131
let chosen = bad_answer_book::ANSWERS
32-
.choose(&mut rand::thread_rng())
32+
.choose(&mut rand::rng())
3333
.expect("not empty");
3434
let res = ctx.reply(*chosen).send().await;
3535
if let Err(err) = res {

src/mods/dice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use rand::Rng;
55
use teloxide_core::prelude::*;
66
use teloxide_core::types::*;
77

8+
use crate::Consumption;
89
use crate::linquebot::*;
910
use crate::utils::telegram::prelude::WarnOnError;
10-
use crate::Consumption;
1111

1212
pub fn dice(ctx: &mut Context, message: &Message) -> Consumption {
1313
use crate::utils::pattern::*;
@@ -68,7 +68,7 @@ pub fn dice(ctx: &mut Context, message: &Message) -> Consumption {
6868

6969
async move {
7070
let results = (0..x)
71-
.map(|_| rand::thread_rng().gen_range(1..=y as u64))
71+
.map(|_| rand::rng().random_range(1..=y as u64))
7272
.collect::<Vec<_>>();
7373

7474
// x 个 u32 的和肯定不会超过 u64,可以放心不会 panic

src/mods/greetings.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{collections::HashMap, time::SystemTime};
22

33
use crate::{
4-
linquebot::{msg_context::Context, types::Consumption, Module, ModuleDescription, ModuleKind},
4+
linquebot::{Module, ModuleDescription, ModuleKind, msg_context::Context, types::Consumption},
55
utils::telegram::prelude::WarnOnError,
66
};
77
use rand::seq::IteratorRandom;
@@ -48,7 +48,7 @@ fn toggle_greeting(ctx: &mut Context, _msg: &Message) -> Consumption {
4848

4949
mod morning {
5050
use crate::{
51-
linquebot::{msg_context::TaskContext, TaskResult},
51+
linquebot::{TaskResult, msg_context::TaskContext},
5252
utils::telegram::prelude::*,
5353
};
5454
use teloxide_core::{prelude::*, types::User};
@@ -131,10 +131,9 @@ fn say_greeting(ctx: &mut Context, msg: &Message) -> Consumption {
131131
.is_ok_and(|dur| dur.as_secs() > 3600))
132132
|| force
133133
{
134-
tokio::spawn(morning::MORNING
135-
.iter()
136-
.choose(&mut rand::thread_rng())
137-
.unwrap()(ctx, user));
134+
tokio::spawn(morning::MORNING.iter().choose(&mut rand::rng()).unwrap()(
135+
ctx, user,
136+
));
138137
}
139138
}
140139
GreetingKind::Night => {

src/mods/rand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
use log::warn;
33
use msg_context::Context;
44
use msg_context::TaskContext;
5-
use rand::seq::SliceRandom;
65
use rand::Rng;
6+
use rand::seq::SliceRandom;
77
use teloxide_core::prelude::*;
88
use teloxide_core::types::*;
99

10+
use crate::Consumption;
1011
use crate::linquebot::*;
1112
use crate::utils::telegram::prelude::*;
1213
use crate::utils::*;
13-
use crate::Consumption;
1414

1515
async fn send_raw_rand(ctx: TaskContext, from: User, text_body: String) {
16-
let result = rand::thread_rng().gen_range(0..=100);
16+
let result = rand::rng().random_range(0..=100);
1717
let msg = format!(
1818
"{} {}",
1919
from.html_link(),
@@ -35,7 +35,7 @@ async fn send_selective_rand(ctx: TaskContext, text_body: String, spliter: &str)
3535
.filter(|str| !str.is_empty())
3636
.collect::<Vec<_>>();
3737

38-
result.shuffle(&mut rand::thread_rng());
38+
result.shuffle(&mut rand::rng());
3939

4040
let result = result.first().unwrap_or(&spliter);
4141

src/mods/waife.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use log::info;
77
use log::warn;
88
use msg_context::Context;
99
use rand::seq::SliceRandom;
10-
use rand::thread_rng;
10+
use rand::rng;
1111
use serde::Deserialize;
1212
use serde::Serialize;
1313
use std::cmp::min;
@@ -299,7 +299,7 @@ fn get_waife(ctx: &mut Context, msg: &Message) -> Consumption {
299299
.await;
300300
}
301301

302-
available_waifes.shuffle(&mut thread_rng());
302+
available_waifes.shuffle(&mut rng());
303303

304304
let mut waife_names = String::new();
305305

0 commit comments

Comments
 (0)