pub trait IntOpsExt: Sized {
const ZERO: Self;
const ONE: Self;
const BITS: u8;
// Required methods
fn checked_shl(&self, rhs: u32) -> Option<Self>;
fn count_ones(&self) -> u32;
fn highest_one(&self) -> Option<u32>;
fn lowest_one(&self) -> Option<u32>;
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
}Expand description
An extension trait for integer operations used by
BitFlags.
It abstracts over the concrete integer types so that generic code can use the same operations.
§Bit width limit
Bit indices are stored as u8, so implementations must report a
BITS value of at most u8::MAX.
This library therefore supports storage types of up to 256 bits.
All primitive integers satisfy this constraint.
Required Associated Constants§
Sourceconst BITS: u8
const BITS: u8
The number of bits in this integer type.
For primitive integers this equals size_of::<Self>() * 8, but
IntOpsExt implementations must return the number of bits the type
can represent as a bit set, which may be smaller for wrapper types.
This value is used to bound valid bit indices for
BitFlag and BitFlags.
It must not exceed u8::MAX, because bit indices are stored as u8.
Required Methods§
Sourcefn checked_shl(&self, rhs: u32) -> Option<Self>
fn checked_shl(&self, rhs: u32) -> Option<Self>
Checked shift left.
Computes self << rhs, returning None if rhs is larger than or
equal to the number of bits in self.
Sourcefn count_ones(&self) -> u32
fn count_ones(&self) -> u32
Returns the number of ones in the binary representation of self.
Sourcefn highest_one(&self) -> Option<u32>
fn highest_one(&self) -> Option<u32>
Returns the index of the highest bit set to one in self, or None
if self is 0.
Sourcefn lowest_one(&self) -> Option<u32>
fn lowest_one(&self) -> Option<u32>
Returns the index of the lowest bit set to one in self, or None
if self is 0.
Sourcefn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
Parses an integer from a string slice with digits in a given base.
This is equivalent to the corresponding inherent method on the concrete integer type.
§Errors
If src is not a valid representation of an integer in the given
radix, returns Err(ParseIntError).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".