From f596b1cdd211c7faf42cbed441bf1d435177d1c7 Mon Sep 17 00:00:00 2001 From: Felix Prillwitz Date: Thu, 23 Jan 2025 19:35:57 +0100 Subject: [PATCH] connect: use small_rng, derive Default --- connect/Cargo.toml | 2 +- connect/src/shuffle_vec.rs | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/connect/Cargo.toml b/connect/Cargo.toml index ee076c3e8..74b21b7dc 100644 --- a/connect/Cargo.toml +++ b/connect/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" futures-util = "0.3" log = "0.4" protobuf = "3.5" -rand = "0.8" +rand = { version = "0.8", default-features = false, features = ["small_rng"] } serde_json = "1.0" thiserror = "2.0" tokio = { version = "1", features = ["macros", "parking_lot", "sync"] } diff --git a/connect/src/shuffle_vec.rs b/connect/src/shuffle_vec.rs index 8e559a671..b7bb5f3d5 100644 --- a/connect/src/shuffle_vec.rs +++ b/connect/src/shuffle_vec.rs @@ -1,10 +1,10 @@ -use rand::{Rng, SeedableRng}; +use rand::{rngs::SmallRng, Rng, SeedableRng}; use std::{ ops::{Deref, DerefMut}, vec::IntoIter, }; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct ShuffleVec { vec: Vec, indices: Option>, @@ -45,12 +45,6 @@ impl From> for ShuffleVec { } } -impl Default for ShuffleVec { - fn default() -> Self { - Self::new() - } -} - impl ShuffleVec { pub fn new() -> Self { Self { @@ -60,7 +54,7 @@ impl ShuffleVec { } pub fn shuffle_with_seed(&mut self, seed: u64) { - self.shuffle_with_rng(rand::rngs::StdRng::seed_from_u64(seed)) + self.shuffle_with_rng(SmallRng::seed_from_u64(seed)) } pub fn shuffle_with_rng(&mut self, mut rng: impl Rng) { @@ -97,7 +91,7 @@ impl ShuffleVec { #[cfg(test)] mod test { - use crate::shuffle_vec::ShuffleVec; + use super::*; use rand::Rng; #[test]