Expand description

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());

Re-exports

pub use rand_core_0_5;
pub use rand_core_0_6;
pub use rand_0_7;
pub use rand_0_8;

Structs

Backward compatibility container object

Forward compatibility container object

Traits

Convert a type into a forward compatibility wrapper object

Helper trait to convert a type for forward compatibility