Skip to content

Commit

Permalink
Update rand requirement from 0.8 to 0.9 in /codec (#106)
Browse files Browse the repository at this point in the history
* Update rand requirement from 0.8 to 0.9 in /codec

Updates the requirements on [rand](https://github.com/rust-random/rand) to permit the latest version.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](rust-random/rand@0.8.0...0.9.0)

---
updated-dependencies:
- dependency-name: rand
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update code to use updated dependency

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Johanna Sörngård <[email protected]>
  • Loading branch information
dependabot[bot] and JSorngard authored Jan 27, 2025
1 parent 475b635 commit 31ef9a0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
54 changes: 48 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cli-clipboard = { version = "0.4", default-features = false, optional = true }
clap = { version = "4.5", default-features = false, features = ["derive", "help", "color", "error-context", "suggestions", "usage"], optional = true }

[dev-dependencies]
rand = { version = "0.8", default-features = false, features = ["alloc", "std", "std_rng"] }
rand = { version = "0.9", default-features = false, features = ["alloc", "std", "std_rng", "thread_rng"] }
unicode-segmentation = { version = "1.12", features = ["no_std"] }

[features]
Expand Down
8 changes: 4 additions & 4 deletions codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ mod tests {
use alloc::string::String;
use core::str;
use rand::{
distributions::{DistString, Distribution},
seq::SliceRandom,
distr::{Distribution, SampleString},
seq::IndexedRandom,
Rng,
};
use unicode_segmentation::UnicodeSegmentation;
Expand All @@ -215,7 +215,7 @@ mod tests {
}
}

impl DistString for PrintableAsciiAndNewline {
impl SampleString for PrintableAsciiAndNewline {
fn append_string<R: Rng + ?Sized>(&self, rng: &mut R, string: &mut String, len: usize) {
string.reserve(len);
for _ in 0..len {
Expand Down Expand Up @@ -276,7 +276,7 @@ mod tests {

// Checking that randomly generated alphanumeric strings are encoded in a lossless fashion, and that they contain a single grapheme cluster
for _ in 0..100 {
let s = PrintableAsciiAndNewline.sample_string(&mut rand::thread_rng(), 100);
let s = PrintableAsciiAndNewline.sample_string(&mut rand::rng(), 100);
let encoded = zalgo_encode(&s).unwrap();
assert_eq!(zalgo_decode(&encoded).unwrap(), s);
assert_eq!(encoded.as_str().graphemes(true).count(), 1)
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rkyv = { version = "0.8", default-features = false, features = ["alloc"], option

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["html_reports"] }
rand = { version = "0.9", default-features = false }
rand = { version = "0.9", default-features = false, features = ["thread_rng"]}

[package.metadata.docs.rs]
# Document all features.
Expand Down
11 changes: 6 additions & 5 deletions common/benches/codec_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::hint::black_box;

use criterion::{criterion_group, criterion_main, Criterion};
use rand::{
distributions::{DistString, Distribution},
seq::SliceRandom,
thread_rng, Rng,
distr::{Distribution, SampleString},
rng,
seq::IndexedRandom,
Rng,
};
use zalgo_codec_common::{zalgo_decode, zalgo_encode, ZalgoString};

Expand All @@ -16,7 +17,7 @@ impl Distribution<char> for PrintableAsciiAndNewline {
}
}

impl DistString for PrintableAsciiAndNewline {
impl SampleString for PrintableAsciiAndNewline {
fn append_string<R: Rng + ?Sized>(&self, rng: &mut R, string: &mut String, len: usize) {
string.reserve(len);
for _ in 0..len {
Expand All @@ -26,7 +27,7 @@ impl DistString for PrintableAsciiAndNewline {
}

fn bench_codec(c: &mut Criterion) {
let string = PrintableAsciiAndNewline.sample_string(&mut thread_rng(), 100_000);
let string = PrintableAsciiAndNewline.sample_string(&mut rng(), 100_000);

let mut group = c.benchmark_group("codec");
group.bench_function("encode", |b| {
Expand Down

0 comments on commit 31ef9a0

Please sign in to comment.