[−][src]Trait intbits::Bits
Extension trait to provide access to individual bits of integers.
Associated Types
type Bits
The (unsigned) type used to represent bits of this type.
For unsigned integers, this is Self
.
For signed integers, this is the unsigned variant of Self
.
Example
assert_eq!(0 as <u8 as Bits>::Bits, 0u8); assert_eq!(0 as <i64 as Bits>::Bits, 0u64); assert_eq!(0 as <usize as Bits>::Bits, 0usize); assert_eq!(0 as <isize as Bits>::Bits, 0usize);
Associated Constants
const N_BITS: u32
Required methods
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
Self: Sized,
I: BitsIndex<Self>,
Self: Sized,
Get a specific bit.
Panics if the index is out of range.
Example
assert_eq!(2u8.bit(0), false); assert_eq!(2u8.bit(1), true); assert_eq!(2u8.bit(2), false);
fn bits<I, R>(self, range: R) -> Self::Bits where
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized,
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized,
Get a range of bits.
The bits are returned in the least significant bits of the return value. The other bits, if any, will be 0.
Empty ranges are allowed, and will result in 0.
Panics when the range bounds are out of range.
Example
assert_eq!(0x45u8.bits(0..4), 5); assert_eq!(0x45u8.bits(4..8), 4); assert_eq!(0xF1u8.bits(1..), 0x78); assert_eq!(0xF1u8.bits(..7), 0x71); assert_eq!(0xF1u8.bits(8..), 0); assert_eq!(0xF1u8.bits(..0), 0);
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
Self: Sized,
I: BitsIndex<Self>,
Self: Sized,
Set a specific bit.
Panics if the index is out of range.
Example
let mut a = 0xFFu8; a.set_bit(3, false); assert_eq!(a, 0xF7);
fn set_bits<I, R>(&mut self, range: R, bits: Self::Bits) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized,
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized,
Set a range of bits.
The bits should be given in the least significant bits of the second argument. The other bits should be 0.
Panics when the range bounds are out of range or when the irrelevant bits of the second argument are not 0.
Example
let mut a = 0xFFu8; a.set_bits(4..8, 3); assert_eq!(a, 0x3F);
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
Self: Sized,
I: BitsIndex<Self>,
Self: Sized,
Get a new integer with one bit set to a specific value.
Panics if the index is out of range.
Example
assert_eq!(0xFFu8.with_bit(3, false), 0xF7);
fn with_bits<I, R>(self, range: R, bits: Self::Bits) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized,
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized,
Get a new integer with a range of bits set to specific values.
The bits should be given in the least significant bits of the second argument. The other bits should be 0.
Panics when the range bounds are out of range or when the irrelevant bits of the second argument are not 0.
Example
assert_eq!(0xFFu8.with_bits(4..8, 3), 0x3F);
Implementors
impl Bits for i8
[src]
type Bits = u8
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u8 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u8) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u8) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for i16
[src]
type Bits = u16
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u16 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u16) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u16) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for i32
[src]
type Bits = u32
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u32 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u32) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u32) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for i64
[src]
type Bits = u64
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u64 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u64) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u64) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for i128
[src]
type Bits = u128
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u128 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u128) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u128) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for isize
[src]
type Bits = usize
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> usize where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: usize) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: usize) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for u8
[src]
type Bits = u8
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u8 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u8) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u8) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for u16
[src]
type Bits = u16
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u16 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u16) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u16) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for u32
[src]
type Bits = u32
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u32 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u32) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u32) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for u64
[src]
type Bits = u64
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u64 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u64) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u64) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for u128
[src]
type Bits = u128
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> u128 where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: u128) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: u128) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
impl Bits for usize
[src]
type Bits = usize
const N_BITS: u32
[src]
fn bit<I>(self, i: I) -> bool where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn bits<I, R>(self, range: R) -> usize where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn set_bit<I>(&mut self, i: I, bit: bool) where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn set_bits<I, R>(&mut self, range: R, bits: usize) where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,
fn with_bit<I>(self, i: I, bit: bool) -> Self where
I: BitsIndex<Self>,
[src]
I: BitsIndex<Self>,
fn with_bits<I, R>(self, range: R, bits: usize) -> Self where
I: BitsIndex<Self>,
R: RangeBounds<I>,
[src]
I: BitsIndex<Self>,
R: RangeBounds<I>,