pub fn genmask_checked_u16(range: RangeInclusive<u32>) -> Option<u16>
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_u16(0..=0), Some(0b1));
assert_eq!(genmask_checked_u16(0..=15), Some(u16::MAX));
assert_eq!(genmask_checked_u16(6..=15), Some(0xffc0));
// `20` is out of the supported bit range.
assert_eq!(genmask_checked_u16(6..=20), None);
// Invalid range where the start is bigger than the end.
assert_eq!(genmask_checked_u16(10..=5), None);