Skip to main content

Rng

Struct Rng 

Source
pub struct Rng<'d, T: Instance> { /* private fields */ }
Expand description

Random number generator. Cancellation disables its peripheral interrupt.

Implementations§

Source§

impl<'d, T: Instance> Rng<'d, T>

Source

pub fn new( inner: Peri<'d, T>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, ) -> Self

Enable the generator. This constructor does not wait for entropy.

Source

pub fn reset(&mut self)

Restart the generator and discard its first ready word on the next read.

This does not wait for clock or seed faults to disappear.

Source

pub fn recover_seed_error(&mut self)

Restart after a seed failure. Subsequent reads report persistent errors.

Source

pub fn try_next_u32(&mut self) -> Result<Option<u32>, Error>

Read one available word without waiting. None means more entropy is needed.

Source

pub fn blocking_next_u32(&mut self) -> Result<u32, Error>

Wait for a random word, reporting hardware errors instead of retrying them.

Source

pub async fn async_next_u32(&mut self) -> Result<u32, Error>

Wait for a word using the RNG interrupt. Errors take priority over data.

Source

pub async fn async_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>

Fill bytes, returning a hardware error if generation fails.

On failure or cancellation an already filled prefix is retained.

Trait Implementations§

Source§

impl<'d, T: Instance> CryptoRng for Rng<'d, T>

Source§

impl<'d, T: Instance> Drop for Rng<'d, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'d, T: Instance> RngCore for Rng<'d, T>

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more
Source§

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>

Fill dest entirely with random data. Read more

Auto Trait Implementations§

§

impl<'d, T> !UnwindSafe for Rng<'d, T>

§

impl<'d, T> Freeze for Rng<'d, T>
where T: Freeze,

§

impl<'d, T> RefUnwindSafe for Rng<'d, T>
where T: RefUnwindSafe,

§

impl<'d, T> Send for Rng<'d, T>

§

impl<'d, T> Sync for Rng<'d, T>
where T: Sync,

§

impl<'d, T> Unpin for Rng<'d, T>
where T: Unpin,

§

impl<'d, T> UnsafeUnpin for Rng<'d, T>
where T: UnsafeUnpin,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CryptoRngCore for T
where T: CryptoRng + RngCore,

Source§

fn as_rngcore(&mut self) -> &mut dyn RngCore

Upcast to an RngCore trait object.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.