Skip to content

Commit

Permalink
Use built-in constant instead of a magic number (#18)
Browse files Browse the repository at this point in the history
In job-security providing functions, it is critically important that
they be fully in line with best coding practices. Hence, instead of
using a well-known(ish!) hardcoded power of two, use u8::MAX to truncate
the u32 into a u8.
  • Loading branch information
Speykious authored Feb 23, 2024
2 parents c65a653 + 195eaf0 commit 3d364e7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn give_up<T: 'static>() -> Box<T> {
let mut rng = oorandom::Rand32::new(seed());

for _ in 0..size {
v.push((rng.rand_u32() % 256) as u8);
v.push((rng.rand_u32() & u32::from(u8::MAX)) as u8);

This comment has been minimized.

Copy link
@turalcar

turalcar Mar 2, 2024

truncation is already well-defined, i.e. both options are pointless

This comment has been minimized.

Copy link
@Speykious

Speykious Mar 2, 2024

Author Owner

I feel stupid now lol

}

crate::transmute(v.into_boxed_slice())
Expand Down

0 comments on commit 3d364e7

Please sign in to comment.