pub trait BitIndex {
// Required methods
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;
}
Expand description
A trait which provides methods for manipulating bits or bit ranges.
Required Methods§
Sourcefn bit_length() -> usize
fn bit_length() -> usize
Length of the implementor type in bits.
Sourcefn bit(&self, pos: usize) -> bool
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()
.
Sourcefn bit_range(&self, pos: Range<usize>) -> Self
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()
Sourcefn set_bit(&mut self, pos: usize, val: bool) -> &mut Self
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()
.
Sourcefn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self
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
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.