#[repr(transparent)]pub struct Bitwise<T>(pub T);
_bit··
only.Expand description
Tuple Fields§
§0: T
Implementations§
Source§impl Bitwise<i8>
§Implementation for i8
.
impl Bitwise<i8>
§Implementation for i8
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: i8, start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn set_value_range(self, value: i8, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: i8,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn set_value_checked_range( self, value: i8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: i8,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn set_checked_value_checked_range( self, value: i8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i8
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i8
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i8
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i8
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i8
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i8
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<i16>
§Implementation for i16
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: i16, start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn set_value_range(self, value: i16, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: i16,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn set_value_checked_range( self, value: i16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: i16,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn set_checked_value_checked_range( self, value: i16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i16
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i16
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i16
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i16
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i16
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i16
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<i32>
§Implementation for i32
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: i32, start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn set_value_range(self, value: i32, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: i32,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn set_value_checked_range( self, value: i32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: i32,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn set_checked_value_checked_range( self, value: i32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i32
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i32
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i32
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i32
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i32
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i32
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<i64>
§Implementation for i64
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: i64, start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn set_value_range(self, value: i64, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: i64,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn set_value_checked_range( self, value: i64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: i64,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn set_checked_value_checked_range( self, value: i64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i64
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i64
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i64
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i64
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i64
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i64
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<i128>
§Implementation for i128
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: i128, start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn set_value_range(self, value: i128, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: i128,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn set_value_checked_range( self, value: i128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: i128,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn set_checked_value_checked_range( self, value: i128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_i128
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i128
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i128
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_i128
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_i128
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_i128
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<isize>
§Implementation for isize
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: isize, start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn set_value_range(self, value: isize, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: isize,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn set_value_checked_range( self, value: isize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: isize,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn set_checked_value_checked_range( self, value: isize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_isize
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_isize
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_isize
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_isize
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_isize
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_isize
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<u8>
§Implementation for u8
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: u8, start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn set_value_range(self, value: u8, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: u8,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn set_value_checked_range( self, value: u8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: u8,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn set_checked_value_checked_range( self, value: u8, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u8
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u8
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u8
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u8
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u8
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u8
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<u16>
§Implementation for u16
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: u16, start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn set_value_range(self, value: u16, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: u16,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn set_value_checked_range( self, value: u16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: u16,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn set_checked_value_checked_range( self, value: u16, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u16
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u16
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u16
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u16
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u16
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u16
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<u32>
§Implementation for u32
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: u32, start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn set_value_range(self, value: u32, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: u32,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn set_value_checked_range( self, value: u32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: u32,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn set_checked_value_checked_range( self, value: u32, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u32
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u32
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u32
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u32
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u32
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u32
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<u64>
§Implementation for u64
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: u64, start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn set_value_range(self, value: u64, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: u64,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn set_value_checked_range( self, value: u64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: u64,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn set_checked_value_checked_range( self, value: u64, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u64
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u64
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u64
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u64
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u64
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u64
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<u128>
§Implementation for u128
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: u128, start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn set_value_range(self, value: u128, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: u128,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn set_value_checked_range( self, value: u128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: u128,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn set_checked_value_checked_range( self, value: u128, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_u128
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u128
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u128
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_u128
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_u128
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_u128
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
impl Bitwise<usize>
§Implementation for usize
.
Sourcepub const fn mask_range(start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn mask_range(start: u32, end: u32) -> Self
_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
Sourcepub const fn mask_checked_range(
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn mask_checked_range( start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
Sourcepub const fn get_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn get_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn get_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn get_value_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn get_value_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn get_value_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn get_value_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn set_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn set_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_value_range(self, value: usize, start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn set_value_range(self, value: usize, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn set_value_checked_range(
self,
value: usize,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn set_value_checked_range( self, value: usize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn set_checked_value_checked_range(
self,
value: usize,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn set_checked_value_checked_range( self, value: usize, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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.
Sourcepub const fn unset_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn unset_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn unset_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn unset_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn flip_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn flip_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn flip_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn flip_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn reverse_range(self, start: u32, end: u32) -> Self
Available on crate feature _bit_usize
only.
pub const fn reverse_range(self, start: u32, end: u32) -> Self
_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
.
Sourcepub const fn reverse_checked_range(
self,
start: u32,
end: u32,
) -> Result<Self, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn reverse_checked_range( self, start: u32, end: u32, ) -> Result<Self, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_usize
only.
pub const fn count_ones_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_usize
only.Counts the number of 1s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_ones_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn count_ones_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
Available on crate feature _bit_usize
only.
pub const fn count_zeros_range(self, start: u32, end: u32) -> u32 ⓘ
_bit_usize
only.Counts the number of 0s in self
from the [start..=end]
range.
§Panics
Panics if start >= BITS || end >= BITS || start > end
.
Sourcepub const fn count_zeros_checked_range(
self,
start: u32,
end: u32,
) -> Result<u32, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn count_zeros_checked_range( self, start: u32, end: u32, ) -> Result<u32, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_first_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_first_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_first_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_first_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_first_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_last_one_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_one_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_last_one_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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
.
Sourcepub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_last_zero_range(self, start: u32, end: u32) -> Option<u32> ⓘ
_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
.
Sourcepub const fn find_last_zero_checked_range(
self,
start: u32,
end: u32,
) -> Result<Option<u32>, MismatchedBounds> ⓘ
Available on crate feature _bit_usize
only.
pub const fn find_last_zero_checked_range( self, start: u32, end: u32, ) -> Result<Option<u32>, MismatchedBounds> ⓘ
_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: Hasher> Hasher for Bitwise<T>
impl<T: Hasher> Hasher for Bitwise<T>
1.26.0 · Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
u128
into this hasher.1.3.0 · Source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
usize
into this hasher.1.26.0 · Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
i128
into this hasher.1.3.0 · Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
isize
into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras
)Source§impl<T: Ord> Ord for Bitwise<T>
impl<T: Ord> Ord for Bitwise<T>
Source§impl<T: PartialOrd> PartialOrd for Bitwise<T>
impl<T: PartialOrd> PartialOrd for Bitwise<T>
impl<T: Copy> Copy for Bitwise<T>
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§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.