Skip to content

Commit df85634

Browse files
authored
Upgrade rand to 0.9 (#666)
Signed-off-by: Nico Burns <nico@nicoburns.com>
1 parent f0abc7e commit df85634

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ utf-8 = "0.7"
4040
criterion = "0.6"
4141
env_logger = "0.10"
4242
libtest-mimic = "0.8.1"
43-
rand = "0.4"
43+
rand = "0.9"
4444
serde_json = "1.0"
4545
typed-arena = "2.0.2"

tendril/examples/fuzz.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ extern crate tendril;
1616

1717
use std::borrow::ToOwned;
1818

19-
use rand::distributions::{IndependentSample, Range};
19+
use rand::distr::uniform::Uniform as Range;
20+
use rand::distr::Distribution;
2021
use rand::Rng;
2122
use tendril::StrTendril;
2223

2324
fn fuzz() {
24-
let mut rng = rand::thread_rng();
25-
let capacity = Range::new(0u32, 1 << 14).ind_sample(&mut rng);
25+
let mut rng = rand::rng();
26+
let capacity = Range::new(0u32, 1 << 14).unwrap().sample(&mut rng);
2627
let mut buf_string = String::with_capacity(capacity as usize);
2728
let mut buf_tendril = StrTendril::with_capacity(capacity);
2829
let mut string_slices = vec![];
@@ -34,8 +35,8 @@ fn fuzz() {
3435
buf_tendril.clear();
3536
}
3637

37-
let dist_action = Range::new(0, 100);
38-
match dist_action.ind_sample(&mut rng) {
38+
let dist_action = Range::new(0, 100).unwrap();
39+
match dist_action.sample(&mut rng) {
3940
0..=15 => {
4041
let (start, end) = random_slice(&mut rng, TEXT);
4142
let snip = &TEXT[start..end];
@@ -82,7 +83,7 @@ fn fuzz() {
8283
},
8384

8485
91..=96 => {
85-
let c = rng.gen();
86+
let c = rng.random();
8687
buf_string.push(c);
8788
assert!(buf_tendril.try_push_char(c).is_ok());
8889
assert_eq!(&*buf_string, &*buf_tendril);
@@ -110,7 +111,7 @@ fn fuzz() {
110111

111112
fn random_boundary<R: Rng>(rng: &mut R, text: &str) -> usize {
112113
loop {
113-
let i = Range::new(0, text.len() + 1).ind_sample(rng);
114+
let i = Range::new(0, text.len() + 1).unwrap().sample(rng);
114115
if text.is_char_boundary(i) {
115116
return i;
116117
}
@@ -119,8 +120,8 @@ fn random_boundary<R: Rng>(rng: &mut R, text: &str) -> usize {
119120

120121
fn random_slice<R: Rng>(rng: &mut R, text: &str) -> (usize, usize) {
121122
loop {
122-
let start = Range::new(0, text.len() + 1).ind_sample(rng);
123-
let end = Range::new(start, text.len() + 1).ind_sample(rng);
123+
let start = Range::new(0, text.len() + 1).unwrap().sample(rng);
124+
let end = Range::new(start, text.len() + 1).unwrap().sample(rng);
124125
if !text.is_char_boundary(start) {
125126
continue;
126127
}

0 commit comments

Comments
 (0)