Skip to main content

UnwrapErr

Struct UnwrapErr 

Source
pub struct UnwrapErr<R: TryRng>(pub R);
Expand description

Wrapper around TryRng implementation which implements Rng by panicking on potential errors.

§Examples

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();
}

Tuple Fields§

§0: R

Implementations§

Source§

impl<'r, R: TryRng + ?Sized> UnwrapErr<&'r mut R>

Source

pub 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§

Source§

impl<R: Clone + TryRng> Clone for UnwrapErr<R>

Source§

fn clone(&self) -> UnwrapErr<R>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Debug + TryRng> Debug for UnwrapErr<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R: Default + TryRng> Default for UnwrapErr<R>

Source§

fn default() -> UnwrapErr<R>

Returns the “default value” for a type. Read more
Source§

impl<R: Hash + TryRng> Hash for UnwrapErr<R>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<R: PartialEq + TryRng> PartialEq for UnwrapErr<R>

Source§

fn eq(&self, other: &UnwrapErr<R>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<R: TryRng> TryRng for UnwrapErr<R>

Source§

type Error = Infallible

The type returned in the event of a RNG error. Read more
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 dst entirely with random data.
Source§

impl<R: Copy + TryRng> Copy for UnwrapErr<R>

Source§

impl<R: Eq + TryRng> Eq for UnwrapErr<R>

Source§

impl<R: TryRng> StructuralPartialEq for UnwrapErr<R>

Source§

impl<R: TryCryptoRng> TryCryptoRng for UnwrapErr<R>

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§

Source§

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

Source§

type Error = <R as TryRng>::Error

👎Deprecated since 0.10.0: use TryRng instead
Error type.
Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

fn next_u32(&mut self) -> u32

Return the next random u32.
Source§

fn next_u64(&mut self) -> u64

Return the next random u64.
Source§

fn fill_bytes(&mut self, dst: &mut [u8])

Fill dest with random data. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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