Divisible

Trait Divisible 

Source
pub trait Divisible<T>: Copy {
    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 + '_;
    fn get(self, index: usize) -> T;
    fn set(self, index: usize, val: T) -> Self;
}
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§

Source

const LOG_N: usize

The log2 of the number of T elements that fit in Self.

Provided Associated Constants§

Source

const N: usize = _

The number of T elements that fit in Self.

Required Methods§

Source

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.

Source

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.

Source

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.

Source

fn get(self, index: usize) -> T

Get element at index (LSB-first ordering).

§Panics

Panics if index >= Self::N.

Source

fn set(self, index: usize, val: T) -> Self

Set element at index (LSB-first ordering), returning modified value.

§Panics

Panics if index >= Self::N.

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.

Implementations on Foreign Types§

Source§

impl Divisible<u8> for u16

Source§

const LOG_N: usize = 1usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u8> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u8

Source§

fn set(self, index: usize, val: u8) -> Self

Source§

impl Divisible<u8> for u32

Source§

const LOG_N: usize = 2usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u8> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u8

Source§

fn set(self, index: usize, val: u8) -> Self

Source§

impl Divisible<u8> for u64

Source§

const LOG_N: usize = 3usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u8> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u8

Source§

fn set(self, index: usize, val: u8) -> Self

Source§

impl Divisible<u8> for u128

Source§

const LOG_N: usize = 4usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u8> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u8> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u8

Source§

fn set(self, index: usize, val: u8) -> Self

Source§

impl Divisible<u16> for u32

Source§

const LOG_N: usize = 1usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u16> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u16> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u16> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u16

Source§

fn set(self, index: usize, val: u16) -> Self

Source§

impl Divisible<u16> for u64

Source§

const LOG_N: usize = 2usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u16> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u16> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u16> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u16

Source§

fn set(self, index: usize, val: u16) -> Self

Source§

impl Divisible<u16> for u128

Source§

const LOG_N: usize = 3usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u16> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u16> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u16> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u16

Source§

fn set(self, index: usize, val: u16) -> Self

Source§

impl Divisible<u32> for u64

Source§

const LOG_N: usize = 1usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u32> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u32> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u32> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u32

Source§

fn set(self, index: usize, val: u32) -> Self

Source§

impl Divisible<u32> for u128

Source§

const LOG_N: usize = 2usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u32> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u32> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u32> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u32

Source§

fn set(self, index: usize, val: u32) -> Self

Source§

impl Divisible<u64> for u128

Source§

const LOG_N: usize = 1usize

Source§

fn value_iter(value: Self) -> impl ExactSizeIterator<Item = u64> + Send + Clone

Source§

fn ref_iter( value: &Self, ) -> impl ExactSizeIterator<Item = u64> + Send + Clone + '_

Source§

fn slice_iter( slice: &[Self], ) -> impl ExactSizeIterator<Item = u64> + Send + Clone + '_

Source§

fn get(self, index: usize) -> u64

Source§

fn set(self, index: usize, val: u64) -> Self

Implementors§

Source§

impl<T: Copy + Send + Sync> Divisible<T> for T

Source§

const LOG_N: usize = 0usize