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
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
cache-on-failure: "true"
- name: Check
run: cargo check
check-with-rand-v09:
check-with-rand-v010:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"
- name: Check with rand v0.9
run: cargo check --features rand-v09
run: cargo check --features rand-v010
tests:
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.3.0
* BREAKING: update rand_core dep to latest `v0.10`. Replace the optional
`rand-v09` feature and re-export with `rand-v10`

See [#5](https://github.com/survived/rand_dev/pull/5)

## v0.2.0
* BREAKING: update rand_core dep to latest `v0.9`
* POSSIBLY BREAKING: the seed is now printed to stderr instead of stdout
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_dev"
version = "0.2.0"
version = "0.3.0"
license = "MIT OR Apache-2.0"
edition = "2024"

Expand All @@ -10,17 +10,17 @@ keywords = ["tests", "reproducibility", "rand"]
repository = "https://github.com/survived/rand_dev"

[dependencies]
rand_core = { version = "0.9", features = ["os_rng"] }
rand_chacha = "0.9"
getrandom = { version = "0.3", default-features = false }
rand_core = { version = "0.10" }
rand_chacha = "0.10"
getrandom = { version = "0.4.2", default-features = false, features = ["sys_rng"] }
const-hex = { version = "1", default-features = false, features = ["alloc"] }

rand = { version = "0.9", optional = true }
rand = { version = "0.10", optional = true }

[dev-dependencies]
rand = "0.9"
rand = "0.10"

[features]
default = []

rand-v09 = ["dep:rand"]
rand-v010 = ["dep:rand"]
2 changes: 1 addition & 1 deletion examples/simple_usage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand_dev = { path = "../../", features = ["rand-v09"] }
rand_dev = { path = "../../", features = ["rand-v010"] }
2 changes: 1 addition & 1 deletion examples/simple_usage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use rand_dev::{DevRng, rand::Rng};
use rand_dev::{DevRng, rand::RngExt};

#[test]
fn it_works() {
Expand Down
37 changes: 20 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![doc = include_str!("../README.md")]

#[cfg(feature = "rand-v09")]
#[cfg(feature = "rand-v010")]
pub use rand;
Comment thread
survived marked this conversation as resolved.

use getrandom::SysRng;
use rand_chacha::ChaCha8Rng;
use rand_core::{CryptoRng, OsRng, RngCore, SeedableRng, TryRngCore};
use rand_core::{Rng, SeedableRng, TryRng};

/// Reproducible random generator for tests
#[derive(Debug, Clone)]
Expand All @@ -28,7 +29,7 @@ impl DevRng {
Err(std::env::VarError::NotUnicode(_)) => {
panic!("provided seed is not a valid unicode")
}
Err(std::env::VarError::NotPresent) => OsRng
Err(std::env::VarError::NotPresent) => SysRng
.try_fill_bytes(&mut seed)
.expect("system randomness unavailable"),
}
Expand Down Expand Up @@ -61,17 +62,19 @@ impl Default for DevRng {
}
}

impl RngCore for DevRng {
fn next_u32(&mut self) -> u32 {
self.0.next_u32()
impl TryRng for DevRng {
type Error = std::convert::Infallible;

fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
self.0.try_next_u32()
}

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

fn fill_bytes(&mut self, dest: &mut [u8]) {
self.0.fill_bytes(dest)
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
self.0.try_fill_bytes(dst)
}
}

Expand All @@ -86,21 +89,21 @@ impl SeedableRng for DevRng {
DevRng(ChaCha8Rng::seed_from_u64(state))
}

fn from_rng(rng: &mut impl RngCore) -> Self {
fn from_rng<R: Rng + ?Sized>(rng: &mut R) -> Self {
Self(ChaCha8Rng::from_rng(rng))
}

fn try_from_rng<R: TryRngCore>(rng: &mut R) -> Result<Self, R::Error> {
fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
ChaCha8Rng::try_from_rng(rng).map(Self)
}

fn from_os_rng() -> Self {
Self(ChaCha8Rng::from_os_rng())
fn fork(&mut self) -> Self {
self.fork()
}

fn try_from_os_rng() -> Result<Self, getrandom::Error> {
ChaCha8Rng::try_from_os_rng().map(Self)
fn try_fork(&mut self) -> Result<Self, std::convert::Infallible> {
Ok(self.fork())
}
}

impl CryptoRng for DevRng {}
impl rand_core::TryCryptoRng for DevRng {}
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand_core::RngCore;
use rand_core::Rng;
use rand_dev::DevRng;

const VAR_NAME: &str = "RUST_TESTS_SEED";
Expand Down
Loading