Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rand requirement from 0.8 to 0.9 in /codec #106

Merged
merged 2 commits into from
Jan 27, 2025
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
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
Loading