pub struct ExternalRng {
pub rng_bytes: [u8; 32],
pub len: usize,
}
Expand description
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
Implementations§
Source§impl ExternalRng
impl ExternalRng
Sourcepub fn copy_into_array<A, T>(slice: &[T]) -> A
pub fn copy_into_array<A, T>(slice: &[T]) -> A
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§
Source§impl Clone for ExternalRng
impl Clone for ExternalRng
Source§fn clone(&self) -> ExternalRng
fn clone(&self) -> ExternalRng
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ExternalRng
impl Debug for ExternalRng
Source§impl RngCore for ExternalRng
implement Trait RngCore for EnternalRng
foucus on fill_bytes
impl RngCore for ExternalRng
implement Trait RngCore for EnternalRng foucus on fill_bytes
Source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
Fill
dest
with random data. Read moreimpl CryptoRng for ExternalRng
implement Trait CryptoRng for EnternalRng empty implement
Auto Trait Implementations§
impl Freeze for ExternalRng
impl RefUnwindSafe for ExternalRng
impl Send for ExternalRng
impl Sync for ExternalRng
impl Unpin for ExternalRng
impl UnwindSafe for ExternalRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more