Skip to content

Commit 027d2e2

Browse files
committed
add error code offset & add comments about alignment
1 parent d78c310 commit 027d2e2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/rng.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ macro_rules! rng_core_transmute {
177177
}
178178

179179
rng_core!(u8, u16, u32);
180+
181+
// Alignment of these types must be a multiple of mem::align_of::<32>()
180182
rng_core_large!(u64, u128);
183+
184+
// A and B must have the same alignment
185+
// rng_core_transmute!(A = B)
186+
// assert!(mem::align_of::<A>() == mem::align_of::<B>())
181187
rng_core_transmute!(
182188
i8 = u8,
183189
i16 = u16,
@@ -222,10 +228,12 @@ impl rand_core::RngCore for Rng {
222228
dest: &mut [u8],
223229
) -> Result<(), rand_core::Error> {
224230
self.fill(dest).map_err(|e| {
225-
core::num::NonZeroU32::new(e as u32)
226-
// This should never fail as long as no enum variant is equal to 0
227-
.expect("Internal hal error")
228-
.into()
231+
core::num::NonZeroU32::new(
232+
rand_core::Error::CUSTOM_START + e as u32,
233+
)
234+
// This should never fail as long as no enum variant is equal to 0
235+
.expect("Internal hal error")
236+
.into()
229237
})
230238
}
231239
}

0 commit comments

Comments
 (0)