#rand #compatibility #compat #random

no-std rand-compat

A compatibility layer for different versions of rand_core

2 releases

0.1.1 Jul 26, 2022
0.1.0 Jul 24, 2022

#8 in #compat

34 downloads per month

MIT license

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

GitHub tag Build Status Crates.io Docs.rs


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

~430–670KB
~12K SLoC