pub struct Rng<'d, T: Instance, M: Mode> { /* private fields */ }
Expand description
A wrapper around an nRF RNG peripheral.
It has a non-blocking API, and a blocking api through rand
.
Implementations§
Source§impl<'d, T: Instance> Rng<'d, T, Blocking>
impl<'d, T: Instance> Rng<'d, T, Blocking>
Sourcepub fn new_blocking(rng: Peri<'d, T>) -> Self
pub fn new_blocking(rng: Peri<'d, T>) -> Self
Creates a new RNG driver from the RNG
peripheral and interrupt.
SAFETY: The future returned from fill_bytes
must not have its lifetime end without running its destructor,
e.g. using mem::forget
.
The synchronous API is safe.
Source§impl<'d, T: Instance> Rng<'d, T, Async>
impl<'d, T: Instance> Rng<'d, T, Async>
Sourcepub fn new(
rng: Peri<'d, T>,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
) -> Self
pub fn new( rng: Peri<'d, T>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, ) -> Self
Creates a new RNG driver from the RNG
peripheral and interrupt.
SAFETY: The future returned from fill_bytes
must not have its lifetime end without running its destructor,
e.g. using mem::forget
.
The synchronous API is safe.
Sourcepub async fn fill_bytes(&mut self, dest: &mut [u8])
pub async fn fill_bytes(&mut self, dest: &mut [u8])
Fill the buffer with random bytes.
Source§impl<'d, T: Instance, M: Mode> Rng<'d, T, M>
impl<'d, T: Instance, M: Mode> Rng<'d, T, M>
Sourcepub fn set_bias_correction(&self, enable: bool)
pub fn set_bias_correction(&self, enable: bool)
Enable or disable the RNG’s bias correction.
Bias correction removes any bias towards a ‘1’ or a ‘0’ in the bits generated. However, this makes the generation of numbers slower.
Defaults to disabled.
Sourcepub fn blocking_fill_bytes(&mut self, dest: &mut [u8])
pub fn blocking_fill_bytes(&mut self, dest: &mut [u8])
Fill the buffer with random bytes, blocking version.
Sourcepub fn blocking_next_u32(&mut self) -> u32
pub fn blocking_next_u32(&mut self) -> u32
Generate a random u32
Sourcepub fn blocking_next_u64(&mut self) -> u64
pub fn blocking_next_u64(&mut self) -> u64
Generate a random u64
Trait Implementations§
Source§impl<'d, T: Instance, M: Mode> RngCore for Rng<'d, T, M>
impl<'d, T: Instance, M: Mode> RngCore for Rng<'d, T, M>
Source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
dest
with random data. Read moreimpl<'d, T: Instance, M: Mode> CryptoRng for Rng<'d, T, M>
impl<'d, T: Instance, M: Mode> CryptoRng for Rng<'d, T, M>
Auto Trait Implementations§
impl<'d, T, M> Freeze for Rng<'d, T, M>where
T: Freeze,
impl<'d, T, M> RefUnwindSafe for Rng<'d, T, M>where
T: RefUnwindSafe,
M: RefUnwindSafe,
impl<'d, T, M> Send for Rng<'d, T, M>where
M: Send,
impl<'d, T, M> Sync for Rng<'d, T, M>
impl<'d, T, M> Unpin for Rng<'d, T, M>
impl<'d, T, M> !UnwindSafe for Rng<'d, T, M>
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CryptoRngCore for T
impl<T> CryptoRngCore for T
Source§fn as_rngcore(&mut self) -> &mut dyn RngCore
fn as_rngcore(&mut self) -> &mut dyn RngCore
RngCore
trait object.Source§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32
.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64
.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest
entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut
wrapper.