Trait BitManip

Source
pub trait BitManip {
    // Required methods
    fn bits(&self) -> Vec<bool>;
    fn bit_ones(&self) -> Vec<u32>;
    fn bit_zeros(&self) -> Vec<u32>;
    fn get_bit_range(&self, start: u32, end: u32) -> Self;
    fn set_bit_range(&self, start: u32, end: u32, val: Self) -> Self;
    fn signed_left_shift(&self, rhs: i32) -> Self;
    fn signed_right_shift(&self, rhs: i32) -> Self;
}
Expand description

A trait that provides utility methods for simple bit manipulation.

Required Methods§

Source

fn bits(&self) -> Vec<bool>

Converts the implementor type into a Vec<bool>.

Source

fn bit_ones(&self) -> Vec<u32>

Returns a vector of every “on” position in the number.

Source

fn bit_zeros(&self) -> Vec<u32>

Returns a vector of every “off” position in the number.

Source

fn get_bit_range(&self, start: u32, end: u32) -> Self

Gets the bits of the value in the the given range between start and end.

start is inclusive, and end is exclusive - a range between 2 and 4 is 2 bits long, and includes positions 2 and 3.

§Panics

This method panics if:

  • start is larger than or equal to end (start >= end).
  • end is larger than Self::MAX (end > Self::MAX).
Source

fn set_bit_range(&self, start: u32, end: u32, val: Self) -> Self

Returns a new value with the bits in the given range between start and end set to the given value.

If the value is too big to be contained in the range, any excess bits are ignored.

start is inclusive, and end is exclusive - a range between 2 and 4 is 2 bits long, and includes positions 2 and 3.

§Panics

This methods panics if:

  • start is larger than or equal to end (start >= end).
  • end is larger than Self::MAX (end > Self::MAX).
Source

fn signed_left_shift(&self, rhs: i32) -> Self

Computes self << rhs if rhs is positive, or self >> rhs if rhs is negative.

Source

fn signed_right_shift(&self, rhs: i32) -> Self

Computes self >> rhs if rhs is positive, or self << rhs if rhs is negative.

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 BitManip for u8

Source§

fn bits(&self) -> Vec<bool>

Source§

fn bit_ones(&self) -> Vec<u32>

Source§

fn bit_zeros(&self) -> Vec<u32>

Source§

fn get_bit_range(&self, start: u32, end: u32) -> Self

Source§

fn set_bit_range(&self, start: u32, end: u32, value: Self) -> Self

Source§

fn signed_left_shift(&self, rhs: i32) -> Self

Source§

fn signed_right_shift(&self, rhs: i32) -> Self

Source§

impl BitManip for u16

Source§

fn bits(&self) -> Vec<bool>

Source§

fn bit_ones(&self) -> Vec<u32>

Source§

fn bit_zeros(&self) -> Vec<u32>

Source§

fn get_bit_range(&self, start: u32, end: u32) -> Self

Source§

fn set_bit_range(&self, start: u32, end: u32, value: Self) -> Self

Source§

fn signed_left_shift(&self, rhs: i32) -> Self

Source§

fn signed_right_shift(&self, rhs: i32) -> Self

Source§

impl BitManip for u32

Source§

fn bits(&self) -> Vec<bool>

Source§

fn bit_ones(&self) -> Vec<u32>

Source§

fn bit_zeros(&self) -> Vec<u32>

Source§

fn get_bit_range(&self, start: u32, end: u32) -> Self

Source§

fn set_bit_range(&self, start: u32, end: u32, value: Self) -> Self

Source§

fn signed_left_shift(&self, rhs: i32) -> Self

Source§

fn signed_right_shift(&self, rhs: i32) -> Self

Source§

impl BitManip for u64

Source§

fn bits(&self) -> Vec<bool>

Source§

fn bit_ones(&self) -> Vec<u32>

Source§

fn bit_zeros(&self) -> Vec<u32>

Source§

fn get_bit_range(&self, start: u32, end: u32) -> Self

Source§

fn set_bit_range(&self, start: u32, end: u32, value: Self) -> Self

Source§

fn signed_left_shift(&self, rhs: i32) -> Self

Source§

fn signed_right_shift(&self, rhs: i32) -> Self

Source§

impl BitManip for u128

Source§

fn bits(&self) -> Vec<bool>

Source§

fn bit_ones(&self) -> Vec<u32>

Source§

fn bit_zeros(&self) -> Vec<u32>

Source§

fn get_bit_range(&self, start: u32, end: u32) -> Self

Source§

fn set_bit_range(&self, start: u32, end: u32, value: Self) -> Self

Source§

fn signed_left_shift(&self, rhs: i32) -> Self

Source§

fn signed_right_shift(&self, rhs: i32) -> Self

Source§

impl BitManip for usize

Source§

fn bits(&self) -> Vec<bool>

Source§

fn bit_ones(&self) -> Vec<u32>

Source§

fn bit_zeros(&self) -> Vec<u32>

Source§

fn get_bit_range(&self, start: u32, end: u32) -> Self

Source§

fn set_bit_range(&self, start: u32, end: u32, value: Self) -> Self

Source§

fn signed_left_shift(&self, rhs: i32) -> Self

Source§

fn signed_right_shift(&self, rhs: i32) -> Self

Implementors§