Skip to content

Commit 030f29d

Browse files
authored
chore: upgrade to rand 0.10 (#637)
1 parent 771372e commit 030f29d

6 files changed

Lines changed: 28 additions & 18 deletions

File tree

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ httparse = { version = "1.8.0", default-features = false, features = ["std"], op
5353
hyper = { version = "1.2", default-features = false, optional = true }
5454
md-5 = { version = "0.10.6", default-features = false, optional = true }
5555
quick-xml = { version = "0.39.0", features = ["serialize", "overlapped-lists"], optional = true }
56-
rand = { version = "0.9", default-features = false, features = ["std", "std_rng", "thread_rng"], optional = true }
56+
rand = { version = "0.10", default-features = false, features = ["std", "std_rng", "thread_rng"], optional = true }
5757
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls-native-roots", "http2"], optional = true }
5858
ring = { version = "0.17", default-features = false, features = ["std"], optional = true }
5959
rustls-pki-types = { version = "1.9", default-features = false, features = ["std"], optional = true }
@@ -83,7 +83,7 @@ integration = ["rand"]
8383
[dev-dependencies] # In alphabetical order
8484
hyper = { version = "1.2", features = ["server"] }
8585
hyper-util = "0.1"
86-
rand = "0.9"
86+
rand = "0.10"
8787
tempfile = "3.1.0"
8888
regex = "1.11.1"
8989
# The "gzip" feature for reqwest is enabled for an integration test.
@@ -92,6 +92,11 @@ reqwest = { version = "0.12", default-features = false, features = ["gzip"] }
9292
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
9393
wasm-bindgen-test = "0.3.50"
9494

95+
[dev-dependencies.getrandom_v04]
96+
package = "getrandom"
97+
version = "0.4"
98+
features = ["wasm_js"]
99+
95100
[dev-dependencies.getrandom_v03]
96101
package = "getrandom"
97102
version = "0.3"
@@ -105,4 +110,4 @@ features = ["js"]
105110
[[test]]
106111
name = "get_range_file"
107112
path = "tests/get_range_file.rs"
108-
required-features = ["fs"]
113+
required-features = ["fs"]

src/azure/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use http::{
4040
HeaderName, Method,
4141
header::{CONTENT_LENGTH, CONTENT_TYPE, HeaderMap, HeaderValue, IF_MATCH, IF_NONE_MATCH},
4242
};
43-
use rand::Rng as _;
43+
use rand::RngExt;
4444
use serde::{Deserialize, Serialize};
4545
use std::collections::HashMap;
4646
use std::sync::Arc;

src/client/backoff.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use rand::{prelude::*, rng};
18+
use rand::{Rng, RngExt, rng};
1919
use std::time::Duration;
2020

2121
/// Exponential backoff with decorrelated jitter algorithm
@@ -56,7 +56,7 @@ pub(crate) struct Backoff {
5656
next_backoff_secs: f64,
5757
max_backoff_secs: f64,
5858
base: f64,
59-
rng: Option<Box<dyn RngCore + Sync + Send>>,
59+
rng: Option<Box<dyn Rng + Sync + Send>>,
6060
}
6161

6262
impl std::fmt::Debug for Backoff {
@@ -81,7 +81,7 @@ impl Backoff {
8181
/// Used [`rand::rng()`] if no rng provided
8282
pub(crate) fn new_with_rng(
8383
config: &BackoffConfig,
84-
rng: Option<Box<dyn RngCore + Sync + Send>>,
84+
rng: Option<Box<dyn Rng + Sync + Send>>,
8585
) -> Self {
8686
let init_backoff = config.init_backoff.as_secs_f64();
8787
Self {
@@ -109,22 +109,27 @@ impl Backoff {
109109

110110
#[cfg(test)]
111111
mod tests {
112+
use std::convert::Infallible;
113+
114+
use rand::{TryRng, rand_core::utils::fill_bytes_via_next_word};
115+
112116
use super::*;
113-
use rand::rand_core::impls::fill_bytes_via_next;
114117

115118
struct FixedRng(u64);
116119

117-
impl RngCore for FixedRng {
118-
fn next_u32(&mut self) -> u32 {
119-
self.0 as _
120+
impl TryRng for FixedRng {
121+
type Error = Infallible;
122+
123+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
124+
Ok(self.0 as _)
120125
}
121126

122-
fn next_u64(&mut self) -> u64 {
123-
self.0
127+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
128+
Ok(self.0)
124129
}
125130

126-
fn fill_bytes(&mut self, dst: &mut [u8]) {
127-
fill_bytes_via_next(self, dst)
131+
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
132+
fill_bytes_via_next_word(dst, || self.try_next_u64())
128133
}
129134
}
130135

src/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
use bytes::Bytes;
3535
use futures::stream::FuturesUnordered;
3636
use futures::{StreamExt, TryStreamExt};
37-
use rand::{Rng, rng};
37+
use rand::{RngExt, rng};
3838
use std::collections::HashSet;
3939
use std::slice;
4040

src/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ mod tests {
246246
use futures::FutureExt;
247247
use parking_lot::Mutex;
248248
use rand::prelude::StdRng;
249-
use rand::{Rng, SeedableRng};
249+
use rand::{RngExt, SeedableRng};
250250

251251
use crate::ObjectStoreExt;
252252
use crate::memory::InMemory;

src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ mod tests {
331331
use crate::Error;
332332

333333
use super::*;
334-
use rand::{Rng, rng};
334+
use rand::{RngExt, rng};
335335
use std::ops::Range;
336336

337337
/// Calls coalesce_ranges and validates the returned data is correct

0 commit comments

Comments
 (0)