[][src]Struct exrng::ExternalRng

pub struct ExternalRng {
    pub rng_bytes: [u8; 32],
    pub len: usize,
}

ExternalRng has all features But use external random source

Fields

rng_bytes: [u8; 32]

bytes to receive external rng when init

len: usize

lenght of RNG

Methods

impl ExternalRng[src]

pub fn copy_into_array<A, T>(slice: &[T]) -> A where
    A: Default + AsMut<[T]>,
    T: Copy
[src]

for no std env if want to convert slice to array

Inputs

  • 'slice' is a slice from raw part

returns

  • array from slice

Examples

use rand_core::{CryptoRng,RngCore};
use exrng::ExternalRng;
fn main(){
use core::slice;
let rng_bytes:[u8;32] = [1u8;32];
let random_ptr: *const u8 = rng_bytes.as_ptr();
let r:&[u8] = unsafe {slice::from_raw_parts(random_ptr, 32)};
let mut rng = ExternalRng {rng_bytes:ExternalRng::copy_into_array(r),len:32};
let mut zero = [0u8; 32];
rng.fill_bytes(&mut zero);
assert_eq!([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], &zero[..]);
}

Trait Implementations

impl Debug for ExternalRng[src]

impl Clone for ExternalRng[src]

impl RngCore for ExternalRng[src]

implement Trait RngCore for EnternalRng foucus on fill_bytes

impl CryptoRng for ExternalRng[src]

implement Trait CryptoRng for EnternalRng empty implement

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]