pub struct BitIndex<T> { /* private fields */ }Expand description
Proof that a value is a valid bit index for T (0 <= index < T::BITS), so
a shift by it can’t overflow, panic, or hit the “shift >= BITS” UB.
Like PowerOfTwo, the rep is the u32 index (never T), so the proof is
Copy regardless of T; consuming ops live in BitIndexOps (signed and
unsigned). No constant-time constructor — shift amounts are public.
use const_num_traits::{BitIndex, BitIndexOps};
let i = BitIndex::<u8>::new(3).unwrap();
assert_eq!(1u8.shl_index(i), 8);
assert_eq!(0x80u8.shr_index(i), 0x10);
assert!(BitIndex::<u8>::new(8).is_none()); // == BITS, rejectedImplementations§
Trait Implementations§
impl<T> Copy for BitIndex<T>
Source§impl TryFrom<u32> for BitIndex<u8>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<u8>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<u16>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<u16>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<u32>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<u32>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<u64>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<u64>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<u128>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<u128>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<usize>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<usize>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<i8>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<i8>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<i16>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<i16>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<i32>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<i32>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<i64>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<i64>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
Source§type Error = TypestateError
type Error = TypestateError
Source§impl TryFrom<u32> for BitIndex<i128>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.
impl TryFrom<u32> for BitIndex<i128>
Checked construction from an index (< BITS); mirrors
BitIndex::new. The source is the u32 index, not the carrier $t.