Struct UnwrapErr
pub struct UnwrapErr<R: TryRng>(pub R);
Wrapper around TryRng implementation which implements [Rng][crate::Rng]
by panicking on potential errors.
Examples
# use rand_core::{UnwrapErr, TryRng, Rng};
fn with_try_rng<R: TryRng>(mut rng: R) {
// rng does not impl Rng:
let _ = rng.try_next_u32(); // okay
// let _ = rng.next_u32(); // error
// An adapter borrowing rng:
let _ = UnwrapErr(&mut rng).next_u32();
// An adapter moving rng:
let mut rng = UnwrapErr(rng);
let _ = rng.next_u32();
}
fn call_with_unsized_try_rng<R: TryRng + ?Sized>(rng: &mut R) {
// R is unsized, thus we must use &mut R:
let mut rng = UnwrapErr(rng);
let _ = rng.next_u32();
}
Fields
0: R
Implementations
impl<'r, R: TryRng + ?Sized> UnwrapErr<&'r mut R>
fn re<'b>(&'b mut self) -> UnwrapErr<&'b mut R> where 'r: 'b,Reborrow with a new lifetime
Rust allows references like
&Tor&mut Tto be "reborrowed" through coercion: essentially, the pointer is copied under a new, shorter, lifetime. Until rfcs#1403 lands, reborrows on user types require a method call.
Trait Implementations
impl<R: Clone + TryRng> Clone for UnwrapErr<R>
fn clone(&self) -> Self
impl<R: Copy + TryRng> Copy for UnwrapErr<R>
impl<R: Debug + TryRng> Debug for UnwrapErr<R>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<R: Default + TryRng> Default for UnwrapErr<R>
fn default() -> Self
impl<R: Eq + TryRng> Eq for UnwrapErr<R>
impl<R: Hash + TryRng> Hash for UnwrapErr<R>
fn hash<__H: Hasher>(&self, state: &mut __H)
impl<R: PartialEq + TryRng> PartialEq for UnwrapErr<R>
fn eq(&self, other: &Self) -> bool
impl<R: PartialEq + TryRng> StructuralPartialEq for UnwrapErr<R>
impl<R: TryCryptoRng> TryCryptoRng for UnwrapErr<R>
impl<R: TryRng> TryRng for UnwrapErr<R>
type Error = never;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>