pub struct NanoArrayRadix<T, const RADIX: usize>(_)
where
    T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul
;
Expand description

A NanoArray with element range 0..RADIX, encoded as a base-RADIX unsigned integer with 1 “digit” per element.

  • T: a backing unsigned integer used to store the encoded number; (n bits).
  • RADIX: determines the range of each element.

The length of the array m is defined by argmax(m) RADIX.pow(m) <= 2.pow(n), i.e. the largest m-digit base-RADIX number must fit in T. Solving the inequality: m = floor(n / log2(RADIX)).

See NanoArray for the supported operations.

Iterator support

  • This array is Copy and offers Self::into_iter() which consumes the array into an iterator of its elements. A non-consuming iterator can be emulated using .clone().

  • This array implements FromIterator and can therefore be Iterator::collected into. It consumes at most Self::LENGTH elements; if the iterator is short, 0 is filled.

Example:

use nanovec::array::*;
type A = NanoArrayRadix<u32, 84>;
let a = [0x4A, 0x3B, 0x2C, 0x1D, 0x0E].iter().collect::<A>();
assert_eq!(a.get(0), 0x4A);
assert_eq!(a.get(1), 0x3B);
let v = a.clone().into_iter().collect::<Vec<_>>();
assert_eq!(v, vec![0x4A, 0x3B, 0x2C, 0x1D, 0x0E]);
assert_eq!(a.get(2), 0x2C);
assert_eq!(a.get(3), 0x1D);
assert_eq!(a.get(4), 0x0E);

Implementations

Width of T, in Bytes.

Width of T, in bits.

The fixed length of this array.

Powers of RADIX; POW[i] == RADIX.pow(i).

Note that we want [u128; Self::LENGTH] but this is not possible in Rust Edition 2021.

Converts this array into an iterator of its elements.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
The underlying representation of this array.
The element type of this array; must be an unsigned primitive integer. Note that it’s not guaranteed that all values that can fit the type is allowed; see Self::max_elem(). Read more
The fixed length of this array.
Creates an all-zero array.
Creates an array from its underlying representation.
Converts the array to its underlying representation.
Returns the maximum element allowed in this array.
Returns a new array = this array with the i-th element set to elem (a.k.a. immutable set index). Panics if the index is out of bounds or the element is out of range. Read more
Sets the i-th element of this array to elem. Panics if the index is out of bounds or the element is out of range. Read more
Returns the i-th element of this array. Behavior when the index is out of bounds is unspecified (okay to panic). Read more
Returns a new array = this array with the i-th element set to elem (a.k.a. immutable set index). Behavior when the index is out of bounds is unspecified (okay to panic). Read more
Sets the i-th element of this array to elem. Behavior when the index is out of bounds is unspecified (okay to panic). Read more
Shifts this array n elements towards the higher index. The lower indices will be left as 0. Behavior when n > Self::LENGTH is unspecified (okay to panic). Read more
Shifts this array n elements towards the lower index The higher indices will be left as 0. Behavior when n > Self::LENGTH is unspecified (okay to panic). Read more
Rotates this array n elements towards the higher index. This is equivalent to rotate_low(Self::LENGTH - n). Panics when n > Self::LENGTH. Read more
Returns the i-th element of this array. Panics if the index is out of bounds. Read more
Rotates this array n elements towards the lower index. This is equivalent to rotate_high(Self::LENGTH - n). Panics when n > Self::LENGTH. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.