Skip to content

Commit

Permalink
Implement assert for bits trait
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Myers <[email protected]>
  • Loading branch information
Elizafox committed Mar 15, 2024
1 parent 28b34e1 commit 4933959
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/util/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use std::mem::size_of;

use num::PrimInt;

// NOTE: do not implement this type for size_of::<Size> > u32::MAX
// (size_of::<Self>() regrettably is not a compile-time expression, so we can't do a static assert)
// NOTE: do not implement this trait for size_of::<Size> > u32::MAX
pub trait IntBitUtil: Sized + PrimInt {
// Count the minimum number of bits required to represent this number
#[allow(clippy::cast_possible_truncation)]
fn bit_length(&self) -> u32 {
assert!(size_of::<Self>() <= u32::MAX as usize);
(size_of::<Self>() - (self.leading_zeros() as usize)) as u32
}
}
Expand Down

0 comments on commit 4933959

Please sign in to comment.