2 releases
0.1.1 | Jul 26, 2022 |
---|---|
0.1.0 | Jul 24, 2022 |
#7 in #compat
9KB
90 lines
rand_compat
A compatibility layer for adaptation between rand
and rand_core
traits of different versions, see the docs for usage details.
Status
lib.rs
:
A compatibility layer for rand
and rand_core
providing adaptation between traits for each version
Forward compatibility (using rand/std
for rand_0_7::OsRng
)
use rand_0_7::rngs::OsRng; use rand_core_0_6::{RngCore, CryptoRng}; use rand_compat::ForwardCompat;
// RngCore + CryptoRng from rand_core@0.6.x fn something<R: RngCore + CryptoRng>(r: &mut R) -> u32 { r.next_u32() }
let mut rng = OsRng; // OsRng from rand@0.7.x (rand_core@0.5.x)
let n = something(&mut rng.forward());
## Backward compatibility (using `rand/std` for `rand_0_8::OsRng`)
use rand_0_8::rngs::OsRng;
use rand_core_0_5::{RngCore, CryptoRng};
use rand_compat::BackwardCompat;
// RngCore + CryptoRng from rand_core@0.5.x
fn something<R: RngCore + CryptoRng>(r: &mut R) -> u32 {
r.next_u32()
}
let mut rng = OsRng; // OsRng from rand@0.8.x (rand_core@0.6.x)
let n = something(&mut rng.backward());
Dependencies
~1.3–2.2MB
~39K SLoC