Struct nanovec::array::NanoArrayRadix
source · [−]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 offersSelf::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 beIterator::collect
ed into. It consumes at mostSelf::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
sourceimpl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> NanoArrayRadix<T, RADIX>
impl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> NanoArrayRadix<T, RADIX>
Trait Implementations
sourceimpl<T: Clone, const RADIX: usize> Clone for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
impl<T: Clone, const RADIX: usize> Clone for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
sourcefn clone(&self) -> NanoArrayRadix<T, RADIX>
fn clone(&self) -> NanoArrayRadix<T, RADIX>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul + Debug, const RADIX: usize> Debug for NanoArrayRadix<T, RADIX>
impl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul + Debug, const RADIX: usize> Debug for NanoArrayRadix<T, RADIX>
sourceimpl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> Default for NanoArrayRadix<T, RADIX>
impl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> Default for NanoArrayRadix<T, RADIX>
sourceimpl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> From<T> for NanoArrayRadix<T, RADIX>
impl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> From<T> for NanoArrayRadix<T, RADIX>
sourceimpl<'a, T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul + 'a, const RADIX: usize> FromIterator<&'a T> for NanoArrayRadix<T, RADIX>
impl<'a, T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul + 'a, const RADIX: usize> FromIterator<&'a T> for NanoArrayRadix<T, RADIX>
sourcefn from_iter<It: IntoIterator<Item = &'a T>>(iter: It) -> Self
fn from_iter<It: IntoIterator<Item = &'a T>>(iter: It) -> Self
Creates a value from an iterator. Read more
sourceimpl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> FromIterator<T> for NanoArrayRadix<T, RADIX>
impl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> FromIterator<T> for NanoArrayRadix<T, RADIX>
sourcefn from_iter<It: IntoIterator<Item = T>>(iter: It) -> Self
fn from_iter<It: IntoIterator<Item = T>>(iter: It) -> Self
Creates a value from an iterator. Read more
sourceimpl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> NanoArray for NanoArrayRadix<T, RADIX>
impl<T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul, const RADIX: usize> NanoArray for NanoArrayRadix<T, RADIX>
type Packed = T
type Packed = T
The underlying representation of this array.
type Element = T
type Element = T
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 moresourcefn from_packed(packed: T) -> Self
fn from_packed(packed: T) -> Self
Creates an array from its underlying representation.
sourcefn with(self, i: usize, elem: T) -> Self
fn with(self, i: usize, elem: T) -> Self
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 moresourcefn set(&mut self, i: usize, elem: T)
fn set(&mut self, i: usize, elem: T)
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 moresourcefn get_unchecked(self, i: usize) -> T
fn get_unchecked(self, i: usize) -> T
Returns the
i
-th element of this array.
Behavior when the index is out of bounds is unspecified (okay to panic). Read moresourcefn with_unchecked(self, i: usize, elem: T) -> Self
fn with_unchecked(self, i: usize, elem: T) -> Self
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 moresourcefn set_unchecked(&mut self, i: usize, elem: T)
fn set_unchecked(&mut self, i: usize, elem: T)
Sets the
i
-th element of this array to elem
.
Behavior when the index is out of bounds is unspecified (okay to panic). Read moresourcefn shift_high(self, n: usize) -> Self
fn shift_high(self, n: usize) -> Self
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 moresourcefn shift_low(self, n: usize) -> Self
fn shift_low(self, n: usize) -> Self
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 moresourcefn rotate_high(self, n: usize) -> Self
fn rotate_high(self, n: usize) -> Self
Rotates this array
n
elements towards the higher index.
This is equivalent to rotate_low(Self::LENGTH - n)
.
Panics when n > Self::LENGTH
. Read moresourcefn get(self, i: usize) -> Self::Element
fn get(self, i: usize) -> Self::Element
Returns the
i
-th element of this array.
Panics if the index is out of bounds. Read moresourcefn rotate_low(self, n: usize) -> Self
fn rotate_low(self, n: usize) -> Self
Rotates this array
n
elements towards the lower index.
This is equivalent to rotate_high(Self::LENGTH - n)
.
Panics when n > Self::LENGTH
. Read moresourceimpl<T: PartialEq, const RADIX: usize> PartialEq<NanoArrayRadix<T, RADIX>> for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
impl<T: PartialEq, const RADIX: usize> PartialEq<NanoArrayRadix<T, RADIX>> for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
sourcefn eq(&self, other: &NanoArrayRadix<T, RADIX>) -> bool
fn eq(&self, other: &NanoArrayRadix<T, RADIX>) -> bool
impl<T: Copy, const RADIX: usize> Copy for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
impl<T: Eq, const RADIX: usize> Eq for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
impl<T, const RADIX: usize> StructuralEq for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
impl<T, const RADIX: usize> StructuralPartialEq for NanoArrayRadix<T, RADIX>where
T: PrimInt + Unsigned + WrappingAdd + WrappingSub + WrappingMul,
Auto Trait Implementations
impl<T, const RADIX: usize> RefUnwindSafe for NanoArrayRadix<T, RADIX>where
T: RefUnwindSafe,
impl<T, const RADIX: usize> Send for NanoArrayRadix<T, RADIX>where
T: Send,
impl<T, const RADIX: usize> Sync for NanoArrayRadix<T, RADIX>where
T: Sync,
impl<T, const RADIX: usize> Unpin for NanoArrayRadix<T, RADIX>where
T: Unpin,
impl<T, const RADIX: usize> UnwindSafe for NanoArrayRadix<T, RADIX>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more