Skip to content

Commit 5de0732

Browse files
authored
Tweak UnwrapErr impl (#66)
1 parent 9eb6381 commit 5de0732

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/unwrap_err.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,24 @@ impl<R: TryRng> TryRng for UnwrapErr<R> {
3434

3535
#[inline]
3636
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
37-
self.0
38-
.try_next_u32()
39-
.map_err(|err| panic!("rand_core::UnwrapErr: failed to unwrap: {err}"))
37+
self.0.try_next_u32().map_err(panic_msg)
4038
}
4139

4240
#[inline]
4341
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
44-
self.0
45-
.try_next_u64()
46-
.map_err(|err| panic!("rand_core::UnwrapErr: failed to unwrap: {err}"))
42+
self.0.try_next_u64().map_err(panic_msg)
4743
}
4844

4945
#[inline]
5046
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
51-
self.0
52-
.try_fill_bytes(dst)
53-
.map_err(|err| panic!("rand_core::UnwrapErr: failed to unwrap: {err}"))
47+
self.0.try_fill_bytes(dst).map_err(panic_msg)
5448
}
5549
}
5650

51+
fn panic_msg(err: impl core::error::Error) -> Infallible {
52+
panic!("rand_core::UnwrapErr: failed to unwrap: {err}")
53+
}
54+
5755
impl<R: TryCryptoRng> TryCryptoRng for UnwrapErr<R> {}
5856

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

0 commit comments

Comments
 (0)