devela::data

Struct Bitwise

Source
#[repr(transparent)]
pub struct Bitwise<T>(pub T);
Available on _bit·· only.
Expand description

Provides constant bitwise operations on T.

It’s implemented for: i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128 and usize.

See also BitOps for the corresponding trait.

Tuple Fields§

§0: T

Implementations§

Source§

impl Bitwise<i8>

§Implementation for i8.

Source

pub const BITS: u32 = 8u32

Available on crate feature _bit_i8 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: i8, start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: i8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: i8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i8 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i8 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i8 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i8 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i8 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i8 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i8 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i8 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i8 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i8 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i8 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i8 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i8 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i8 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<i16>

§Implementation for i16.

Source

pub const BITS: u32 = 16u32

Available on crate feature _bit_i16 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: i16, start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: i16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: i16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i16 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i16 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i16 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i16 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i16 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i16 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i16 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i16 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i16 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i16 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i16 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i16 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i16 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i16 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<i32>

§Implementation for i32.

Source

pub const BITS: u32 = 32u32

Available on crate feature _bit_i32 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: i32, start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: i32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: i32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i32 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i32 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i32 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i32 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i32 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i32 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i32 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i32 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i32 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i32 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i32 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i32 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i32 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i32 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<i64>

§Implementation for i64.

Source

pub const BITS: u32 = 64u32

Available on crate feature _bit_i64 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: i64, start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: i64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: i64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i64 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i64 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i64 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i64 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i64 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i64 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i64 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i64 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i64 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i64 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i64 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i64 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i64 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i64 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<i128>

§Implementation for i128.

Source

pub const BITS: u32 = 128u32

Available on crate feature _bit_i128 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: i128, start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: i128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: i128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_i128 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_i128 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i128 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i128 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_i128 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_i128 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i128 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i128 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i128 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i128 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i128 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i128 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_i128 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_i128 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<isize>

§Implementation for isize.

Source

pub const BITS: u32 = 64u32

Available on crate feature _bit_isize only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: isize, start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: isize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: isize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_isize only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_isize only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_isize only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_isize only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_isize only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_isize only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_isize only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_isize only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_isize only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_isize only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_isize only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_isize only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_isize only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_isize only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<u8>

§Implementation for u8.

Source

pub const BITS: u32 = 8u32

Available on crate feature _bit_u8 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: u8, start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: u8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: u8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u8 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u8 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u8 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u8 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u8 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u8 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u8 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u8 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u8 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u8 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u8 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u8 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u8 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u8 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<u16>

§Implementation for u16.

Source

pub const BITS: u32 = 16u32

Available on crate feature _bit_u16 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: u16, start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: u16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: u16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u16 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u16 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u16 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u16 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u16 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u16 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u16 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u16 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u16 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u16 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u16 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u16 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u16 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u16 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<u32>

§Implementation for u32.

Source

pub const BITS: u32 = 32u32

Available on crate feature _bit_u32 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: u32, start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: u32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: u32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u32 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u32 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u32 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u32 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u32 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u32 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u32 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u32 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u32 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u32 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u32 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u32 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u32 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u32 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<u64>

§Implementation for u64.

Source

pub const BITS: u32 = 64u32

Available on crate feature _bit_u64 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: u64, start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: u64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: u64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u64 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u64 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u64 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u64 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u64 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u64 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u64 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u64 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u64 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u64 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u64 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u64 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u64 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u64 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<u128>

§Implementation for u128.

Source

pub const BITS: u32 = 128u32

Available on crate feature _bit_u128 only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: u128, start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: u128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: u128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_u128 only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_u128 only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u128 only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u128 only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_u128 only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_u128 only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u128 only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u128 only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u128 only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u128 only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u128 only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u128 only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_u128 only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_u128 only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source§

impl Bitwise<usize>

§Implementation for usize.

Source

pub const BITS: u32 = 64u32

Available on crate feature _bit_usize only.

The size in bits.

Source

pub const fn mask_range(start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Returns a new bitmask of 1s from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    2.8 ns   163.0 ns
  64    2.0 ns    21.6 ns
  32    2.4 ns    12.1 ns
  16    2.6 ns     7.6 ns
   8    2.9 ns     8.4 ns
Source

pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Returns a new bitmask of ones from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

§Benchmarks

The current algorithm used can be more than 1 order of magnitude more efficient than a naive loop that sets the individual bits, as well as much more consistant across the spectrum of bitsizes.

The following table shows the compared benchmark for start=0 and end=BITS-1 measured on an i5-8350U CPU @ 1.70 Ghz:

bits   current    naive
----   -------   --------
 128    3.7 ns   145.0 ns
  64    3.2 ns    38.2 ns
  32    3.2 ns     9.0 ns
  16    3.2 ns     7.0 ns
   8    3.1 ns     6.7 ns
Source

pub const fn get_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Gets the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Gets the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn get_value_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Gets the value of the bits in self from the [start..=end] range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Gets the value of the bits in self from the [start..=end] checked range.

Sets the rest of the bits to 0.

The bits in the specified range are shifted rightwards so that the least significant bit (LSB) aligns with the units place, forming the integer value.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Sets the bits in self to 1, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Sets the bits in self to 1, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_value_range(self, value: usize, start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Sets the given value into the bits from the [start..=end] range.

Leaves the rest of the bits unchanged.

The value is first masked to fit the size of the range, and then it is inserted into the specified bit range of self, replacing the existing bits in that range. The rest of the bits in self remain unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn set_value_checked_range( self, value: usize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Sets the given value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn set_checked_value_checked_range( self, value: usize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Sets the given checked value into the bits from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS, MismatchedIndices if start > end, and DataOverflow if value does not fit within the specified bit range.

Source

pub const fn unset_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Unsets the bits in self to 0, from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Unsets the bits in self to 0, from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn flip_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Flips the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Flips the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn reverse_range(self, start: u32, end: u32) -> Self

Available on crate feature _bit_usize only.

Reverses the order of the bits in self from the [start..=end] range.

Leaves the rest of the bits unchanged.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds>

Available on crate feature _bit_usize only.

Reverses the order of the bits in self from the [start..=end] checked range.

Leaves the rest of the bits unchanged.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_ones_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_usize only.

Counts the number of 1s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_usize only.

Counts the number of 1s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn count_zeros_range(self, start: u32, end: u32) -> u32

Available on crate feature _bit_usize only.

Counts the number of 0s in self from the [start..=end] range.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds>

Available on crate feature _bit_usize only.

Counts the number of 0s in self from the [start..=end] checked range.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_usize only.

Finds the index of the first 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_usize only.

Finds the index of the first 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_usize only.

Finds the index of the first 0 in self from the [start..=end] range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_usize only.

Finds the index of the first 0 in self from the [start..=end] checked range.

Returns None if there are no bits unset.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_usize only.

Finds the index of the last 1 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_usize only.

Finds the index of the last 1 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Source

pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32>

Available on crate feature _bit_usize only.

Finds the index of the last 0 in self from the [start..=end] range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Panics

Panics if start >= BITS || end >= BITS || start > end.

Source

pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds>

Available on crate feature _bit_usize only.

Finds the index of the last 0 in self from the [start..=end] checked range.

Returns None if there are no bits set.

The index is relative to the entire sequence of self, not to the given start.

§Errors

Returns IndexOutOfBounds if start >= BITS || end >= BITS and MismatchedIndices if start > end.

Trait Implementations§

Source§

impl<T: Binary> Binary for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone> Clone for Bitwise<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display> Display for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Hash> Hash for Bitwise<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Hasher> Hasher for Bitwise<T>

Source§

fn finish(&self) -> u64

Returns the hash value for the values written so far. Read more
Source§

fn write(&mut self, bytes: &[u8])

Writes some data into this Hasher. Read more
1.3.0 · Source§

fn write_u8(&mut self, i: u8)

Writes a single u8 into this hasher.
1.3.0 · Source§

fn write_u16(&mut self, i: u16)

Writes a single u16 into this hasher.
1.3.0 · Source§

fn write_u32(&mut self, i: u32)

Writes a single u32 into this hasher.
1.3.0 · Source§

fn write_u64(&mut self, i: u64)

Writes a single u64 into this hasher.
1.26.0 · Source§

fn write_u128(&mut self, i: u128)

Writes a single u128 into this hasher.
1.3.0 · Source§

fn write_usize(&mut self, i: usize)

Writes a single usize into this hasher.
1.3.0 · Source§

fn write_i8(&mut self, i: i8)

Writes a single i8 into this hasher.
1.3.0 · Source§

fn write_i16(&mut self, i: i16)

Writes a single i16 into this hasher.
1.3.0 · Source§

fn write_i32(&mut self, i: i32)

Writes a single i32 into this hasher.
1.3.0 · Source§

fn write_i64(&mut self, i: i64)

Writes a single i64 into this hasher.
1.26.0 · Source§

fn write_i128(&mut self, i: i128)

Writes a single i128 into this hasher.
1.3.0 · Source§

fn write_isize(&mut self, i: isize)

Writes a single isize into this hasher.
Source§

fn write_length_prefix(&mut self, len: usize)

🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a length prefix into this hasher, as part of being prefix-free. Read more
Source§

fn write_str(&mut self, s: &str)

🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a single str into this hasher. Read more
Source§

impl<T: LowerExp> LowerExp for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: LowerHex> LowerHex for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Octal> Octal for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord> Ord for Bitwise<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Bitwise<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Bitwise<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: UpperExp> UpperExp for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: UpperHex> UpperHex for Bitwise<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy> Copy for Bitwise<T>

Source§

impl<T: Eq> Eq for Bitwise<T>

Auto Trait Implementations§

§

impl<T> Freeze for Bitwise<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Bitwise<T>
where T: RefUnwindSafe,

§

impl<T> Send for Bitwise<T>
where T: Send,

§

impl<T> Sync for Bitwise<T>
where T: Sync,

§

impl<T> Unpin for Bitwise<T>
where T: Unpin,

§

impl<T> UnwindSafe for Bitwise<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByteSized for T

Source§

const BYTE_ALIGN: usize = _

The alignment of this type in bytes.
Source§

const BYTE_SIZE: usize = _

The size of this type in bytes.
Source§

fn byte_align(&self) -> usize

Returns the alignment of this type in bytes.
Source§

fn byte_size(&self) -> usize

Returns the size of this type in bytes. Read more
Source§

fn ptr_size_ratio(&self) -> [usize; 2]

Returns the size ratio between Ptr::BYTES and BYTE_SIZE. Read more
Source§

impl<T, R> Chain<R> for T
where T: ?Sized,

Source§

fn chain<F>(self, f: F) -> R
where F: FnOnce(Self) -> R, Self: Sized,

Chain a function which takes the parameter by value.
Source§

fn chain_ref<F>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Chain a function which takes the parameter by shared reference.
Source§

fn chain_mut<F>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Chain a function which takes the parameter by exclusive reference.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ExtAny for T
where T: Any + ?Sized,

Source§

fn type_id() -> TypeId

Returns the TypeId of Self. Read more
Source§

fn type_of(&self) -> TypeId

Returns the TypeId of self. Read more
Source§

fn type_name(&self) -> &'static str

Returns the type name of self. Read more
Source§

fn type_is<T: 'static>(&self) -> bool

Returns true if Self is of type T. Read more
Source§

fn as_any_ref(&self) -> &dyn Any
where Self: Sized,

Upcasts &self as &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any
where Self: Sized,

Upcasts &mut self as &mut dyn Any. Read more
Source§

fn as_any_box(self: Box<Self>) -> Box<dyn Any>
where Self: Sized,

Upcasts Box<self> as Box<dyn Any>. Read more
Source§

fn downcast_ref<T: 'static>(&self) -> Option<&T>

Available on crate feature unsafe_layout only.
Returns some shared reference to the inner value if it is of type T. Read more
Source§

fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Available on crate feature unsafe_layout only.
Returns some exclusive reference to the inner value if it is of type T. Read more
Source§

impl<T> ExtMem for T
where T: ?Sized,

Source§

const NEEDS_DROP: bool = _

Know whether dropping values of this type matters, in compile-time.
Source§

fn mem_align_of<T>() -> usize

Returns the minimum alignment of the type in bytes. Read more
Source§

fn mem_align_of_val(&self) -> usize

Returns the alignment of the pointed-to value in bytes. Read more
Source§

fn mem_size_of<T>() -> usize

Returns the size of a type in bytes. Read more
Source§

fn mem_size_of_val(&self) -> usize

Returns the size of the pointed-to value in bytes. Read more
Source§

fn mem_copy(&self) -> Self
where Self: Copy,

Bitwise-copies a value. Read more
Source§

fn mem_needs_drop(&self) -> bool

Returns true if dropping values of this type matters. Read more
Source§

fn mem_drop(self)
where Self: Sized,

Drops self by running its destructor. Read more
Source§

fn mem_forget(self)
where Self: Sized,

Forgets about self without running its destructor. Read more
Source§

fn mem_replace(&mut self, other: Self) -> Self
where Self: Sized,

Replaces self with other, returning the previous value of self. Read more
Source§

fn mem_take(&mut self) -> Self
where Self: Default,

Replaces self with its default value, returning the previous value of self. Read more
Source§

fn mem_swap(&mut self, other: &mut Self)
where Self: Sized,

Swaps the value of self and other without deinitializing either one. Read more
Source§

unsafe fn mem_zeroed<T>() -> T

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

fn mem_as_bytes(&self) -> &[u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &[u8]. Read more
Source§

fn mem_as_bytes_mut(&mut self) -> &mut [u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &mut [u8]. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T> Hook for T

Source§

fn hook_ref<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Applies a function which takes the parameter by shared reference, and then returns the (possibly) modified owned value. Read more
Source§

fn hook_mut<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Applies a function which takes the parameter by exclusive reference, and then returns the (possibly) modified owned value. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Ungil for T
where T: Send,