Trait TryRngCore

Source
pub trait TryRngCore {
    type Error: Debug + Display;

    // Required methods
    fn try_next_u32(&mut self) -> Result<u32, Self::Error>;
    fn try_next_u64(&mut self) -> Result<u64, Self::Error>;
    fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error>;

    // Provided methods
    fn unwrap_err(self) -> UnwrapErr<Self>
       where Self: Sized { ... }
    fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self> { ... }
    fn read_adapter(&mut self) -> RngReadAdapter<'_, Self> 
       where Self: Sized { ... }
}
Expand description

A potentially fallible variant of RngCore

This trait is a generalization of RngCore to support potentially- fallible IO-based generators such as OsRng.

All implementations of RngCore automatically support this TryRngCore trait, using Infallible as the associated Error type.

An implementation of this trait may be made compatible with code requiring an RngCore through TryRngCore::unwrap_err. The resulting RNG will panic in case the underlying fallible RNG yields an error.

Required Associated Types§

Source

type Error: Debug + Display

The type returned in the event of a RNG error.

Required Methods§

Source

fn try_next_u32(&mut self) -> Result<u32, Self::Error>

Return the next random u32.

Source

fn try_next_u64(&mut self) -> Result<u64, Self::Error>

Return the next random u64.

Source

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

Fill dest entirely with random data.

Provided Methods§

Source

fn unwrap_err(self) -> UnwrapErr<Self>
where Self: Sized,

Wrap RNG with the UnwrapErr wrapper.

Source

fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>

Wrap RNG with the UnwrapMut wrapper.

Source

fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>
where Self: Sized,

Convert an RngCore to a RngReadAdapter.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§