Trait bit::BitIndex
[−]
[src]
pub trait BitIndex { fn bit_length() -> usize; fn bit(&self, pos: usize) -> bool; fn bit_range(&self, pos: Range<usize>) -> Self; fn set_bit(&mut self, pos: usize, val: bool) -> &mut Self; fn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self; }
A trait which provides methods for manipulating bits or bit ranges.
Required Methods
fn bit_length() -> usize
Length of the implementor type in bits.
fn bit(&self, pos: usize) -> bool
Obtains the value of the bit at the given position, being 0 the least significant bit.
Panics
This method will panic if the index is out of bounds, e.g: pos >= Self::bit_length()
.
fn bit_range(&self, pos: Range<usize>) -> Self
Obtains the value of the bits inside the given range, being 0 the least significant bit.
Panics
This method will panic if:
- Range
start
is equal or higher thanend
- Range
end
is out of bounds, e.g:pos.end > Self::bit_length()
fn set_bit(&mut self, pos: usize, val: bool) -> &mut Self
Sets the value of the bit at the given position, being 0 the least significant bit.
Panics
This method will panic if the index is out of bounds, e.g: pos >= Self::bit_length()
.
fn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self
Sets the value of the bits inside the given range, being 0 the least significant bit.
Panics
This method will panic if:
- Range
start
is equal or higher thanend
- Range
end
is out of bounds, e.g:pos.end > Self::bit_length()
- Value doesn't fit in the given range
Implementors
impl BitIndex for u8
impl BitIndex for u16
impl BitIndex for u32
impl BitIndex for u64
impl BitIndex for usize