CircularIndex

Trait CircularIndex 

Source
pub trait CircularIndex<'a, const N: usize, T: 'a> {
Show 13 methods // 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_contiguous( &'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_contiguous( &'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_contiguous( &'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

Indexing CircularArray operations.

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, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
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, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.get_raw([0, 0]), &8);
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_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter().cloned().collect::<Vec<_>>(), &[
    0, 1, 2,
    3, 4, 5,
    6, 7, 8
]);
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_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
Source

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

Iterate over all elements of the specified axis and index, aligned to the offset.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter_index(0, 0).cloned().collect::<Vec<_>>(), &[
    0, 3, 6
]);
Source

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

Iterate over all elements of the specified axis and index, aligned to the offset in contiguous order.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter_index_contiguous(0, 0).cloned().collect::<Vec<_>>(), &[
    6, 0, 3
]);
Source

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

Iterate over all elements of the specified axis and index, ignoring the offset.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter_index_raw(0, 0).cloned().collect::<Vec<_>>(), &[
    8,
    2,
    5
]);
Source

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

Iterate over all elements of the specified axis and range, aligned to the offset. This is equivalent to CircularIndex::iter_slice where all axis ranges are exhaustive with the exception of the specified axis.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter_range(0, 1..3).cloned().collect::<Vec<_>>(), &[
    1, 2,
    4, 5,
    7, 8
]);
Source

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

Iterate over all elements of the specified axis and range, aligned to the offset in contiguous order. This is equivalent to CircularIndex::iter_slice_contiguous where all axis ranges are exhaustive with the exception of the specified axis.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter_range(0, 1..3).cloned().collect::<Vec<_>>(), &[
    1, 2,
    4, 5,
    7, 8
]);
Source

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

Iterate over all elements of the specified axis and range, ignoring the offset. 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_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);
assert_eq!(array.iter_range_raw(0, 1..3).cloned().collect::<Vec<_>>(), &[
    6, 7,
    0, 1,
    3, 4
]);
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_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4
]);

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

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

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

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

assert_eq!(array.iter_slice_contiguous([1..3, 1..3]).cloned().collect::<Vec<_>>(), &[
    8, 7,
    5, 4
]);
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, ignoring the offset.

§Example
let mut array = CircularArray::new_offset([3, 3], [1, 1], vec![
    8, 6, 7,
    2, 0, 1,
    5, 3, 4,
]);
assert_eq!(array.iter_slice_raw([1..3, 1..3]).cloned().collect::<Vec<_>>(), &[
    0, 1,
    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>