Function genmask_checked_u64

Source
pub fn genmask_checked_u64(range: RangeInclusive<u32>) -> Option<u64>
Expand description

Creates a contiguous bitmask for the given range by validating the range at runtime.

Returns None if the range is invalid, i.e.: if the start is greater than the end or if the range is outside of the representable range for the type.

ยงExamples

assert_eq!(genmask_checked_u64(0..=0), Some(0b1));
assert_eq!(genmask_checked_u64(0..=63), Some(u64::MAX));
assert_eq!(genmask_checked_u64(21..=39), Some(0x0000_00ff_ffe0_0000));

// `80` is out of the supported bit range.
assert_eq!(genmask_checked_u64(21..=80), None);

// Invalid range where the start is bigger than the end.
assert_eq!(genmask_checked_u64(15..=8), None);