CircularIndex

Trait CircularIndex 

Source
pub trait CircularIndex<'a, const N: usize, T: 'a> {
    // Required methods
    fn get(&'a self, index: [usize; N]) -> &'a T;
    fn get_raw(&'a self, index: [usize; N]) -> &'a T;
    fn iter(&'a self) -> impl ExactSizeIterator<Item = &'a T>;
    fn iter_raw(&'a self) -> impl ExactSizeIterator<Item = &'a T>;
    fn iter_index(
        &'a self,
        axis: usize,
        index: usize,
    ) -> impl ExactSizeIterator<Item = &'a T>;
    fn iter_index_raw(
        &'a self,
        axis: usize,
        index: usize,
    ) -> impl ExactSizeIterator<Item = &'a T>;
    fn iter_range(
        &'a self,
        axis: usize,
        range: Range<usize>,
    ) -> impl ExactSizeIterator<Item = &'a T>;
    fn iter_range_raw(
        &'a self,
        axis: usize,
        range: Range<usize>,
    ) -> impl ExactSizeIterator<Item = &'a T>;
    fn iter_slice(
        &'a self,
        slice: [Range<usize>; N],
    ) -> impl ExactSizeIterator<Item = &'a T>;
    fn iter_slice_raw(
        &'a self,
        slice: [Range<usize>; N],
    ) -> impl ExactSizeIterator<Item = &'a T>;
}
Expand description

Operations for retrieving elements from the array.

Required Methods§

Source

fn get(&'a self, index: [usize; N]) -> &'a T

Get a reference to the element at the given index, aligned to the offset.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
    2, 0, 1,
    5, 3, 4,
    8, 6, 7,
]);
assert_eq!(array.get([0, 0]), &0);
Source

fn get_raw(&'a self, index: [usize; N]) -> &'a T

Get a reference to the element at the given index. This does not account for the offset. See CircularArray::offset.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
    2, 0, 1,
    5, 3, 4,
    8, 6, 7,
]);
assert_eq!(array.get_raw([0, 0]), &2);
Source

fn iter(&'a self) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of the inner array, aligned to the offset.

§Example
let mut array = CircularArray::new([3, 3], vec![
    0, 1, 2,
    3, 4, 5,
    6, 7, 8,
]);
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter().cloned().collect::<Vec<_>>(), &[
    3,  4,  5,
    6,  7,  8,
    9, 10, 11,
]);
Source

fn iter_raw(&'a self) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of the inner array, ignoring the offset.

§Example
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
    9, 10, 11,
    3,  4,  5,
    6,  7,  8,
]);
Source

fn iter_index( &'a self, axis: usize, index: usize, ) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of index for the given axis, aligned to the offset.

§Example
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter_index(0, 0).cloned().collect::<Vec<_>>(), &[
    3, 6, 9
]);
Source

fn iter_index_raw( &'a self, axis: usize, index: usize, ) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of index for the given axis, ignoring the offset.

§Example
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter_index_raw(0, 0).cloned().collect::<Vec<_>>(), &[
    9, 3, 6
]);
Source

fn iter_range( &'a self, axis: usize, range: Range<usize>, ) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of the given index range for the given axis, aligned to the offset. This is equivalent to CircularIndex::iter_slice where all axis ranges are exhaustive except for the specified axis.

§Example
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter_range(0, 1..3).cloned().collect::<Vec<_>>(), &[
     4,  5,
     7,  8,
    10, 11,
]);
Source

fn iter_range_raw( &'a self, axis: usize, range: Range<usize>, ) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of the given index range for the given axis. This is equivalent to CircularIndex::iter_slice_raw where all axis ranges are exhaustive except for the specified axis.

§Example
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter_range_raw(0, 1..3).cloned().collect::<Vec<_>>(), &[
    10, 11,
     4,  5,
     7,  8,
]);
Source

fn iter_slice( &'a self, slice: [Range<usize>; N], ) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of the given index slice, aligned to the offset.

§Example
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter_slice([0..2, 0..2]).cloned().collect::<Vec<_>>(), &[
    3, 4,
    6, 7,
]);
Source

fn iter_slice_raw( &'a self, slice: [Range<usize>; N], ) -> impl ExactSizeIterator<Item = &'a T>

Iterate over all elements of the given index slice.

§Example
let mut array = CircularArray::new([3, 3], Vec::from_iter(0..3 * 3));
// A circular array of values `3..12`.
array.push_front(1, &[9, 10, 11]);

assert_eq!(array.iter_slice_raw([0..2, 0..2]).cloned().collect::<Vec<_>>(), &[
    9, 10,
    3,  4,
]);

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.

Implementors§

Source§

impl<'a, const N: usize, A: AsRef<[T]>, T: 'a> CircularIndex<'a, N, T> for CircularArray<N, A, T>