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 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§
Required Methods§
Sourcefn try_next_u32(&mut self) -> Result<u32, Self::Error>
fn try_next_u32(&mut self) -> Result<u32, Self::Error>
Return the next random u32
.
Sourcefn try_next_u64(&mut self) -> Result<u64, Self::Error>
fn try_next_u64(&mut self) -> Result<u64, Self::Error>
Return the next random u64
.
Provided Methods§
Sourcefn unwrap_err(self) -> UnwrapErr<Self>where
Self: Sized,
fn unwrap_err(self) -> UnwrapErr<Self>where
Self: Sized,
Wrap RNG with the UnwrapErr
wrapper.
Sourcefn read_adapter(&mut self) -> RngReadAdapter<'_, Self> ⓘwhere
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self> ⓘwhere
Self: Sized,
Convert an RngCore
to a RngReadAdapter
.