#compatibility #compat #rand-core

no-std rand06-compat

Compatibility wrapper between rand_core 0.6 and 0.9

1 unstable release

Uses new Rust 2024

0.1.0 Mar 17, 2025

#11 in #compat

Download history 436/week @ 2025-09-24 315/week @ 2025-10-01 372/week @ 2025-10-08 523/week @ 2025-10-15 411/week @ 2025-10-22 412/week @ 2025-10-29 361/week @ 2025-11-05 185/week @ 2025-11-12 585/week @ 2025-11-19 623/week @ 2025-11-26 810/week @ 2025-12-03 413/week @ 2025-12-10 636/week @ 2025-12-17 186/week @ 2025-12-24 260/week @ 2025-12-31 308/week @ 2026-01-07

1,503 downloads per month

MIT/Apache

9KB
89 lines

rand06-compat

This crate provides a compatibility wrapper between versions 0.6 and 0.9 of rand_core.

Warning about no_std ⚠️

Supporting fallible RNGs is tricky to do in a clean manner. This compat wrapper hardcodes an error code of 1 in the case that the RNG fails.

PRs welcome for a better solution.

Example

use rand_core_06::RngCore as RngCore06;
use rand_core::OsRng;
use rand06_compat::Rand0_6CompatExt;

// This function requires an RNG implementing the `0.6` trait.
fn foo<R>(rng: &mut R) where R: RngCore06 {
    let num: u32 = rng.next_u32();
    println!("random number: {}", num);
}

// Pass in the RNG from `0.9` using compat trait.
foo(&mut OsRng.compat())

Dependencies

~245KB