Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ futures = "0.3"
integer-encoding = "4"
lz4 = { version = "1.23", optional = true }
parking_lot = "0.12"
rand = { version = "0.9", default-features = false, features = ["thread_rng"] }
rand = { version = "0.10", default-features = false, features = ["thread_rng"] }
rustls = { version = "0.23", optional = true, default-features = false, features = ["logging", "ring", "std", "tls12"] }
snap = { version = "1", optional = true }
thiserror = "2.0"
Expand Down
27 changes: 14 additions & 13 deletions src/backoff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand::prelude::*;
use rand::{Rng, RngExt};
use std::ops::ControlFlow;
use std::time::Duration;
use tracing::info;
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct Backoff {
base: f64,
total: f64,
deadline: Option<f64>,
rng: Option<Box<dyn RngCore + Sync + Send>>,
rng: Option<Box<dyn Rng + Sync + Send>>,
}

impl std::fmt::Debug for Backoff {
Expand All @@ -83,10 +83,7 @@ impl Backoff {
/// Creates a new `Backoff` with the optional `rng`
///
/// Used [`rand::rng()`] if no rng provided
pub fn new_with_rng(
config: &BackoffConfig,
rng: Option<Box<dyn RngCore + Sync + Send>>,
) -> Self {
pub fn new_with_rng(config: &BackoffConfig, rng: Option<Box<dyn Rng + Sync + Send>>) -> Self {
let init_backoff = config.init_backoff.as_secs_f64();
Self {
init_backoff,
Expand Down Expand Up @@ -175,6 +172,8 @@ impl Iterator for Backoff {
#[cfg(test)]
mod tests {
use super::*;
use rand::{TryRng, rand_core::utils::fill_bytes_via_next_word};
use std::convert::Infallible;

#[test]
fn test_backoff() {
Expand Down Expand Up @@ -243,17 +242,19 @@ mod tests {
}
}

impl RngCore for ConstantRng {
fn next_u32(&mut self) -> u32 {
(self.value >> 32) as u32
impl TryRng for ConstantRng {
type Error = Infallible;

fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
Ok((self.value >> 32) as u32)
}

fn next_u64(&mut self) -> u64 {
self.value
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
Ok(self.value)
}

fn fill_bytes(&mut self, _dest: &mut [u8]) {
unimplemented!()
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
fill_bytes_via_next_word(dst, || self.try_next_u64())
}
}
}
2 changes: 1 addition & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand::prelude::*;
use rand::seq::SliceRandom;
use std::fmt::Display;
use std::future::Future;
use std::ops::ControlFlow;
Expand Down