Skip to content

Commit

Permalink
1.41 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Jan 3, 2025
1 parent f4eeb2b commit eefd670
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,14 @@ where
{
}

/// Generate bit mask with `len` 1 bits. (Rust 1.41.0 compatible)
const fn ones(len: usize) -> usize {
let shr = usize::BITS - len as u32;

Check failure on line 1026 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (MSRV)

no associated item named `BITS` found for type `usize` in the current scope
let first_shr = shr / 2;
// right shift in two passes to avoid overflow
0usize.wrapping_sub(1) >> first_shr >> (shr - first_shr)
}

// === pack ===

pub(crate) trait Pack<C: cfg::Config>: Sized {
Expand Down Expand Up @@ -1048,14 +1056,8 @@ pub(crate) trait Pack<C: cfg::Config>: Sized {
/// left by `Self::SHIFT` bits to calculate this type's `MASK`.
///
/// This is computed automatically based on `Self::LEN`.
const BITS: usize = {
if Self::LEN == 0 {
0
} else {
let shift = 1 << (Self::LEN - 1);
shift | (shift - 1)
}
};
const BITS: usize = ones(Self::LEN);

/// The number of bits to shift a number to pack it into a usize with other
/// values.
///
Expand Down

0 comments on commit eefd670

Please sign in to comment.