pub trait BitOps:
Copy
+ Integer
+ BitAnd<Output = Self>
+ Shl<Output = Self>
+ Shr<Output = Self>
+ From<u8> {
// Provided methods
fn is_flag(&self) -> bool { ... }
fn is_bit_set(&self, bit: u8) -> bool { ... }
fn is_flag_set(&self, flag: Self) -> bool { ... }
fn bits_as_int(&self, bit: u8, count: u8) -> Self { ... }
}
Expand description
Provided Methods§
Sourcefn is_flag(&self) -> bool
fn is_flag(&self) -> bool
Returns whether this number only has one bit set.
§Examples
use bitops::BitOps;
assert!(0b1000.is_flag());
assert!(!0b1001.is_flag());
Sourcefn is_bit_set(&self, bit: u8) -> bool
fn is_bit_set(&self, bit: u8) -> bool
Sourcefn is_flag_set(&self, flag: Self) -> bool
fn is_flag_set(&self, flag: Self) -> bool
Returns whether the given flag is set.
§Examples
use bitops::BitOps;
assert!(0b11010.is_flag_set(0b11000));
Sourcefn bits_as_int(&self, bit: u8, count: u8) -> Self
fn bits_as_int(&self, bit: u8, count: u8) -> Self
Returns a number with bit 0 starting at the given bit and up to count
left most bits.
This is basically a right shift by bit
and masked with (1 << count) - 1
.
§Panics
Panics if bit
is greater than the number of bits in this Integer.
§Examples
use bitops::BitOps;
assert_eq!(0xab000.bits_as_int(12, 8), 0xab);
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.