1use crate::{Infallible, TryCryptoRng, TryRng};
2
3#[derive(#[automatically_derived]
impl<R: ::core::fmt::Debug + TryRng> ::core::fmt::Debug for UnwrapErr<R> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "UnwrapErr",
&&self.0)
}
}Debug, #[automatically_derived]
impl<R: ::core::default::Default + TryRng> ::core::default::Default for
UnwrapErr<R> {
#[inline]
fn default() -> UnwrapErr<R> {
UnwrapErr(::core::default::Default::default())
}
}Default, #[automatically_derived]
impl<R: ::core::clone::Clone + TryRng> ::core::clone::Clone for UnwrapErr<R> {
#[inline]
fn clone(&self) -> UnwrapErr<R> {
UnwrapErr(::core::clone::Clone::clone(&self.0))
}
}Clone, #[automatically_derived]
impl<R: ::core::marker::Copy + TryRng> ::core::marker::Copy for UnwrapErr<R> {
}Copy, #[automatically_derived]
impl<R: ::core::cmp::Eq + TryRng> ::core::cmp::Eq for UnwrapErr<R> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<R>;
}
}Eq, #[automatically_derived]
impl<R: ::core::cmp::PartialEq + TryRng> ::core::cmp::PartialEq for
UnwrapErr<R> {
#[inline]
fn eq(&self, other: &UnwrapErr<R>) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl<R: ::core::hash::Hash + TryRng> ::core::hash::Hash for UnwrapErr<R> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash)]
30pub struct UnwrapErr<R: TryRng>(pub R);
31
32impl<R: TryRng> TryRng for UnwrapErr<R> {
33 type Error = Infallible;
34
35 #[inline]
36 fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
37 self.0.try_next_u32().map_err(panic_msg)
38 }
39
40 #[inline]
41 fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
42 self.0.try_next_u64().map_err(panic_msg)
43 }
44
45 #[inline]
46 fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
47 self.0.try_fill_bytes(dst).map_err(panic_msg)
48 }
49}
50
51fn panic_msg(err: impl core::error::Error) -> Infallible {
52 {
::core::panicking::panic_fmt(format_args!("rand_core::UnwrapErr: failed to unwrap: {0}",
err));
}panic!("rand_core::UnwrapErr: failed to unwrap: {err}")
53}
54
55impl<R: TryCryptoRng> TryCryptoRng for UnwrapErr<R> {}
56
57impl<'r, R: TryRng + ?Sized> UnwrapErr<&'r mut R> {
58 #[inline(always)]
64 pub fn re<'b>(&'b mut self) -> UnwrapErr<&'b mut R>
65 where
66 'r: 'b,
67 {
68 UnwrapErr(self.0)
69 }
70}