Trait BitIndex

Source
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§

Source

fn bit_length() -> usize

Length of the implementor type in bits.

Source

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().

Source

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 than end
  • Range end is out of bounds, e.g: pos.end > Self::bit_length()
Source

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().

Source

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 than end
  • 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.

Implementations on Foreign Types§

Source§

impl BitIndex for u8

Source§

fn bit_length() -> usize

Source§

fn bit(&self, pos: usize) -> bool

Source§

fn bit_range(&self, pos: Range<usize>) -> Self

Source§

fn set_bit(&mut self, pos: usize, val: bool) -> &mut Self

Source§

fn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self

Source§

impl BitIndex for u16

Source§

fn bit_length() -> usize

Source§

fn bit(&self, pos: usize) -> bool

Source§

fn bit_range(&self, pos: Range<usize>) -> Self

Source§

fn set_bit(&mut self, pos: usize, val: bool) -> &mut Self

Source§

fn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self

Source§

impl BitIndex for u32

Source§

fn bit_length() -> usize

Source§

fn bit(&self, pos: usize) -> bool

Source§

fn bit_range(&self, pos: Range<usize>) -> Self

Source§

fn set_bit(&mut self, pos: usize, val: bool) -> &mut Self

Source§

fn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self

Source§

impl BitIndex for u64

Source§

fn bit_length() -> usize

Source§

fn bit(&self, pos: usize) -> bool

Source§

fn bit_range(&self, pos: Range<usize>) -> Self

Source§

fn set_bit(&mut self, pos: usize, val: bool) -> &mut Self

Source§

fn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self

Source§

impl BitIndex for usize

Source§

fn bit_length() -> usize

Source§

fn bit(&self, pos: usize) -> bool

Source§

fn bit_range(&self, pos: Range<usize>) -> Self

Source§

fn set_bit(&mut self, pos: usize, val: bool) -> &mut Self

Source§

fn set_bit_range(&mut self, pos: Range<usize>, val: Self) -> &mut Self

Implementors§