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: RImplementations§
Source§impl<'r, R: TryRng + ?Sized> UnwrapErr<&'r mut R>
impl<'r, R: TryRng + ?Sized> UnwrapErr<&'r mut R>
Sourcepub fn re<'b>(&'b mut self) -> UnwrapErr<&'b mut R>where
'r: 'b,
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: TryRng> TryRng for UnwrapErr<R>
impl<R: TryRng> TryRng for UnwrapErr<R>
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a RNG error. Read more
impl<R: Copy + TryRng> Copy for UnwrapErr<R>
impl<R: Eq + TryRng> Eq for UnwrapErr<R>
impl<R: TryRng> StructuralPartialEq for UnwrapErr<R>
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 Rwhere
R: TryRng,
impl<R> TryRngCore for Rwhere
R: TryRng,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more