Skip to main content

IntOpsExt

Trait IntOpsExt 

Source
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§

Source

const ZERO: Self

The value 0.

Source

const ONE: Self

The value 1.

Source

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§

Source

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.

Source

fn count_ones(&self) -> u32

Returns the number of ones in the binary representation of self.

Source

fn highest_one(&self) -> Option<u32>

Returns the index of the highest bit set to one in self, or None if self is 0.

Source

fn lowest_one(&self) -> Option<u32>

Returns the index of the lowest bit set to one in self, or None if self is 0.

Source

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".

Implementations on Foreign Types§

Source§

impl IntOpsExt for i8

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for i16

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for i32

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for i64

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for i128

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for isize

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for u8

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for u16

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for u32

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for u64

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for u128

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Source§

impl IntOpsExt for usize

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

const BITS: u8

Source§

fn checked_shl(&self, rhs: u32) -> Option<Self>

Source§

fn count_ones(&self) -> u32

Source§

fn lowest_one(&self) -> Option<u32>

Source§

fn highest_one(&self) -> Option<u32>

Source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Implementors§