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§
Sourcefn get_bit_range(&self, start: u32, end: u32) -> Self
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 toend
(start >= end
).end
is larger thanSelf::MAX
(end > Self::MAX
).
Sourcefn set_bit_range(&self, start: u32, end: u32, val: Self) -> Self
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 toend
(start >= end
).end
is larger thanSelf::MAX
(end > Self::MAX
).
Sourcefn signed_left_shift(&self, rhs: i32) -> Self
fn signed_left_shift(&self, rhs: i32) -> Self
Computes self << rhs
if rhs
is positive, or self >> rhs
if rhs
is negative.
Sourcefn signed_right_shift(&self, rhs: i32) -> Self
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.