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 version of RngCore
.
This trait is primarily used for IO-based generators such as OsRng
.
Most of higher-level generic code in the rand
crate is built on top
of the the RngCore
trait. Users can transform a fallible RNG
(i.e. TryRngCore
implementor) into an “infallible” (but potentially
panicking) RNG (i.e. RngCore
implementor) using the UnwrapErr
wrapper.
RngCore
implementors also usually implement TryRngCore
with the Error
associated type being equal to Infallible
.
In other words, users can use TryRngCore
to generalize over fallible and
infallible RNGs.
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
.