pub trait NanoArray: Copy + Clone + Sized + PartialEq + Eq {
type Packed;
type Element: PrimInt + Unsigned;
const LENGTH: usize;
Show 14 methods
fn new() -> Self;
fn from_packed(packed: Self::Packed) -> Self;
fn packed(self) -> Self::Packed;
fn max_elem() -> Self::Element;
fn get_unchecked(self, i: usize) -> Self::Element;
fn shift_high(self, n: usize) -> Self;
fn shift_low(self, n: usize) -> Self;
fn get(self, i: usize) -> Self::Element { ... }
fn with(self, i: usize, elem: Self::Element) -> Self { ... }
fn set(&mut self, i: usize, elem: Self::Element) { ... }
fn with_unchecked(self, i: usize, elem: Self::Element) -> Self { ... }
fn set_unchecked(&mut self, i: usize, elem: Self::Element) { ... }
fn rotate_high(self, n: usize) -> Self { ... }
fn rotate_low(self, n: usize) -> Self { ... }
}
Expand description
A fixed-length array of unsigned integers in the range 0..(Self::max_elem())
.
May be stored in a compressed format, and therefore does not provide references; this means no
core::ops::Index
or core::ops::IndexMut
required, and no slicing.
The following operations are required to be implemented:
- read element at index —
Self::get_unchecked
- write element at index —
Self::set_unchecked
and/orSelf::with_unchecked
- shift and rotate
Required Associated Types
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()
.
Required Associated Constants
Required Methods
sourcefn from_packed(packed: Self::Packed) -> Self
fn from_packed(packed: Self::Packed) -> Self
Creates an array from its underlying representation.
sourcefn get_unchecked(self, i: usize) -> Self::Element
fn get_unchecked(self, i: usize) -> Self::Element
Returns the i
-th element of this array.
Behavior when the index is out of bounds is unspecified (okay to panic).
sourcefn 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).
Example: shift_high([A, B, C, D], 1) == [0, A, B, C]
Provided Methods
Returns the i
-th element of this array.
Panics if the index is out of bounds.
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.
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.
sourcefn with_unchecked(self, i: usize, elem: Self::Element) -> Self
fn with_unchecked(self, i: usize, elem: Self::Element) -> 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).
Implementer must provide at least one of Self::with_unchecked
, Self::set_unchecked
.
sourcefn set_unchecked(&mut self, i: usize, elem: Self::Element)
fn set_unchecked(&mut self, i: usize, elem: Self::Element)
Sets the i
-th element of this array to elem
.
Behavior when the index is out of bounds is unspecified (okay to panic).
Implementer must provide at least one of Self::with_unchecked
, Self::set_unchecked
.
sourcefn 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
.
Example: rotate_high([A, B, C, D], 1) == [D, A, B, C]
Implementer must provide at least one of Self::rotate_high
, Self::rotate_low
.
sourcefn 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
.
Example: rotate_low([A, B, C, D], 1) == [B, C, D, A]
Implementer must provide at least one of Self::rotate_high
, Self::rotate_low
.