pub trait BitUtils: Sized + Copy {
// Required methods
fn bit(self, index: u8) -> bool;
fn try_bit(self, index: u8) -> Option<bool>;
fn with_bit(self, index: u8, value: bool) -> Self;
fn try_with_bit(self, index: u8, value: bool) -> Option<Self>;
fn bits(self, start: u8, end: u8) -> Self;
fn try_bits(self, start: u8, end: u8) -> Option<Self>;
fn with_bits(self, start: u8, end: u8, value: Self) -> Self;
fn try_with_bits(self, start: u8, end: u8, value: Self) -> Option<Self>;
}Expand description
Provides methods for querying and modifying the value of specific bits. Convention is LSB0.
Required Methods§
Sourcefn bit(self, index: u8) -> bool
fn bit(self, index: u8) -> bool
Returns whether the bit at index is set or not. Indices out of range always return false.
Sourcefn try_bit(self, index: u8) -> Option<bool>
fn try_bit(self, index: u8) -> Option<bool>
Returns whether the bit at index is set or not. If out of range, returns None.
Sourcefn with_bit(self, index: u8, value: bool) -> Self
fn with_bit(self, index: u8, value: bool) -> Self
Sets the state of the bit at index. Indices out of range return the value unmodified.
Sourcefn try_with_bit(self, index: u8, value: bool) -> Option<Self>
fn try_with_bit(self, index: u8, value: bool) -> Option<Self>
Sets the state of the bit at index. If out of range, returns None.
Sourcefn bits(self, start: u8, end: u8) -> Self
fn bits(self, start: u8, end: u8) -> Self
Extracts the value between bits start (inclusive) and end (exclusive). Bits out of
range are always zero and invalid ranges return zero.
Sourcefn try_bits(self, start: u8, end: u8) -> Option<Self>
fn try_bits(self, start: u8, end: u8) -> Option<Self>
Extracts the value between bits start (inclusive) and end (exclusive). If the range is
invalid, returns None.
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.