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 &T or &mut T to 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) -> UnwrapErr<R>

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() -> UnwrapErr<R>

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: &UnwrapErr<R>) -> 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 = Infallible;
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>

Auto Trait Implementations

impl<R> Freeze for UnwrapErr<R> where R: Freeze,

impl<R> RefUnwindSafe for UnwrapErr<R> where R: RefUnwindSafe,

impl<R> Send for UnwrapErr<R> where R: Send,

impl<R> Sync for UnwrapErr<R> where R: Sync,

impl<R> Unpin for UnwrapErr<R> where R: Unpin,

impl<R> UnsafeUnpin for UnwrapErr<R> where R: UnsafeUnpin,

impl<R> UnwindSafe for UnwrapErr<R> where R: UnwindSafe,

Blanket Implementations

impl<R> CryptoRng for UnwrapErr<R> where R: TryCryptoRng<Error = Infallible> + ?Sized,

impl<R> Rng for UnwrapErr<R> where R: TryRng<Error = Infallible> + ?Sized,

fn next_u32(&mut self) -> u32
fn next_u64(&mut self) -> u64
fn fill_bytes(&mut self, dst: &mut [u8])

impl<R> RngCore for UnwrapErr<R> where R: Rng,

impl<R> TryRngCore for UnwrapErr<R> where R: TryRng,

type Error = <R as TryRng>::Error;

impl<T> Any for UnwrapErr<R> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for UnwrapErr<R> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for UnwrapErr<R> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for UnwrapErr<R> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for UnwrapErr<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for UnwrapErr<R> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for UnwrapErr<R> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for UnwrapErr<R> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>