pub trait Divisible<T>: Sized {
const LOG_N: usize;
const N: usize = _;
// Required methods
fn value_iter(
value: Self,
) -> impl ExactSizeIterator<Item = T> + Send + Clone;
fn ref_iter(
value: &Self,
) -> impl ExactSizeIterator<Item = T> + Send + Clone + '_;
fn slice_iter(
slice: &[Self],
) -> impl ExactSizeIterator<Item = T> + Send + Clone + '_;
unsafe fn get_unchecked(&self, index: usize) -> T;
unsafe fn set_unchecked(&mut self, index: usize, val: T);
fn broadcast(val: T) -> Self;
fn from_iter(iter: impl Iterator<Item = T>) -> Self;
// Provided methods
fn get(&self, index: usize) -> T { ... }
fn set(&mut self, index: usize, val: T) { ... }
}Expand description
Divides an underlier type into smaller underliers in memory and iterates over them.
Divisible provides iteration over the subdivisions of an underlier type, guaranteeing that
iteration proceeds from the least significant bits to the most significant bits, regardless of
the CPU architecture’s endianness.
§Endianness Handling
To ensure consistent LSB-to-MSB iteration order across all platforms:
- On little-endian systems: elements are naturally ordered LSB-to-MSB in memory, so iteration proceeds forward through the array
- On big-endian systems: elements are ordered MSB-to-LSB in memory, so iteration is reversed to achieve LSB-to-MSB order
This abstraction allows code to work with subdivided underliers in a platform-independent way while maintaining the invariant that the first element always represents the least significant portion of the value.
Required Associated Constants§
Provided Associated Constants§
Required Methods§
Sourcefn value_iter(value: Self) -> impl ExactSizeIterator<Item = T> + Send + Clone
fn value_iter(value: Self) -> impl ExactSizeIterator<Item = T> + Send + Clone
Returns an iterator over subdivisions of this underlier value, ordered from LSB to MSB.
Sourcefn ref_iter(
value: &Self,
) -> impl ExactSizeIterator<Item = T> + Send + Clone + '_
fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = T> + Send + Clone + '_
Returns an iterator over subdivisions of this underlier reference, ordered from LSB to MSB.
Sourcefn slice_iter(
slice: &[Self],
) -> impl ExactSizeIterator<Item = T> + Send + Clone + '_
fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = T> + Send + Clone + '_
Returns an iterator over subdivisions of a slice of underliers, ordered from LSB to MSB.
Sourceunsafe fn get_unchecked(&self, index: usize) -> T
unsafe fn get_unchecked(&self, index: usize) -> T
Get element at index (LSB-first ordering) without bounds checking.
§Safety
The caller must ensure that index < Self::N.
Sourceunsafe fn set_unchecked(&mut self, index: usize, val: T)
unsafe fn set_unchecked(&mut self, index: usize, val: T)
Set element at index (LSB-first ordering) in place, without bounds checking.
§Safety
The caller must ensure that index < Self::N.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.