pub trait CircularMut<'a, const N: usize, T> {
// Required methods
fn get_mut(&mut self, index: [usize; N]) -> &mut T;
fn get_mut_raw(&mut self, index: [usize; N]) -> &mut T;
fn push_front(&'a mut self, axis: usize, el: &'a [T]);
fn push_front_iter<'b, I>(&'a mut self, axis: usize, el: I)
where I: IntoIterator<IntoIter: ExactSizeIterator, Item = &'b T>,
T: 'b;
fn push_front_raw(&'a mut self, axis: usize, el: &'a [T]);
fn push_front_raw_iter<'b, I>(&'a mut self, axis: usize, el: I)
where I: IntoIterator<IntoIter: ExactSizeIterator, Item = &'b T>,
T: 'b;
fn push_back(&'a mut self, axis: usize, el: &'a [T]);
fn push_back_iter<'b, I>(&'a mut self, axis: usize, el: I)
where I: IntoIterator<IntoIter: ExactSizeIterator, Item = &'b T>,
T: 'b;
fn push_back_raw(&'a mut self, axis: usize, el: &'a [T]);
fn push_back_raw_iter<'b, I>(&'a mut self, axis: usize, el: I)
where I: IntoIterator<IntoIter: ExactSizeIterator, Item = &'b T>,
T: 'b;
fn translate_front<'b, F>(
&'a mut self,
axis: usize,
n: usize,
origin: [usize; N],
el_fn: F,
)
where T: 'b,
F: FnMut([Range<usize>; N]) -> &'b [T];
fn translate_back<'b, F>(
&'a mut self,
axis: usize,
n: usize,
origin: [usize; N],
el_fn: F,
)
where T: 'b,
F: FnMut([Range<usize>; N]) -> &'b [T];
}Expand description
Mutating CircularArray operations.
Required Methods§
Sourcefn get_mut(&mut self, index: [usize; N]) -> &mut T
fn get_mut(&mut self, index: [usize; N]) -> &mut T
Get a mutable 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_mut([0, 0]), &mut 0);Sourcefn get_mut_raw(&mut self, index: [usize; N]) -> &mut T
fn get_mut_raw(&mut self, index: [usize; N]) -> &mut T
Get a mutable 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_mut_raw([0, 0]), &mut 2);Sourcefn push_front(&'a mut self, axis: usize, el: &'a [T])
fn push_front(&'a mut self, axis: usize, el: &'a [T])
Push elements to the front of the given axis, aligned to the offset.
Elements must be an exact multiple of the slice size for the given axis.
See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_front(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
11, 9, 10,
3, 4, 5,
6, 7, 8,
]);Sourcefn push_front_iter<'b, I>(&'a mut self, axis: usize, el: I)
fn push_front_iter<'b, I>(&'a mut self, axis: usize, el: I)
Push elements to the front of the given axis, aligned to the offset.
Elements must be an exact multiple of the slice size for the given axis.
See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_front_iter(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
11, 9, 10,
3, 4, 5,
6, 7, 8,
]);Sourcefn push_front_raw(&'a mut self, axis: usize, el: &'a [T])
fn push_front_raw(&'a mut self, axis: usize, el: &'a [T])
Push elements to the front of the given axis, taking into account only
the offset of the given axis. Elements must be an exact multiple of
the slice size for the given axis. See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_front_raw(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
9, 10, 11,
3, 4, 5,
6, 7, 8,
]);Sourcefn push_front_raw_iter<'b, I>(&'a mut self, axis: usize, el: I)
fn push_front_raw_iter<'b, I>(&'a mut self, axis: usize, el: I)
Push elements to the front of the given axis, taking into account the
offsets of all axes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_front_raw_iter(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
9, 10, 11,
3, 4, 5,
6, 7, 8,
]);Sourcefn push_back(&'a mut self, axis: usize, el: &'a [T])
fn push_back(&'a mut self, axis: usize, el: &'a [T])
Push elements to the back of the given axis, taking into account the
offsets of all exes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_back(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
0, 1, 2,
3, 4, 5,
11, 9, 10,
]);Sourcefn push_back_iter<'b, I>(&'a mut self, axis: usize, el: I)
fn push_back_iter<'b, I>(&'a mut self, axis: usize, el: I)
Push elements to the back of the given axis, taking into account the
offsets of all exes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_back_iter(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
0, 1, 2,
3, 4, 5,
11, 9, 10,
]);Sourcefn push_back_raw(&'a mut self, axis: usize, el: &'a [T])
fn push_back_raw(&'a mut self, axis: usize, el: &'a [T])
Push elements to the back of the given axis, taking into account the
offsets of all axes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_back_raw(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
0, 1, 2,
3, 4, 5,
9, 10, 11,
]);Sourcefn push_back_raw_iter<'b, I>(&'a mut self, axis: usize, el: I)
fn push_back_raw_iter<'b, I>(&'a mut self, axis: usize, el: I)
Push elements to the back of the given axis, taking into account the
offsets of all axes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len.
§Example
let mut array = CircularArray::new_offset([3, 3], [1, 0], vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
]);
array.push_back_raw_iter(1, &[9, 10, 11]);
assert_eq!(array.iter_raw().cloned().collect::<Vec<_>>(), &[
0, 1, 2,
3, 4, 5,
9, 10, 11,
]);Sourcefn translate_front<'b, F>(
&'a mut self,
axis: usize,
n: usize,
origin: [usize; N],
el_fn: F,
)
fn translate_front<'b, F>( &'a mut self, axis: usize, n: usize, origin: [usize; N], el_fn: F, )
Translate the array by n on the given axis, inserting elements to the
front of the array.
Requires specifying the array origin of the CircularArray relative to
translation. N dimensional index range ([Range<usize>; N]) will be passed
to the el_fn for slicing a source buffer to retrieve the new elements.
Note that the caler should ensure that a translation of n is within the
source array bounds prior to calling this function.
In the following example, we pre-calculate the [crate::Strides] of
the source array to flatten the N dimensional index into a contiguous
range (requires feature flag strides). Alternatively, the index range can
be passed to 3rd party crates for slicing operations.
// A [5, 5] source array.
let src = [
0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11, 12, 13, 14,
15, 16, 17, 18, 19,
20, 21, 22, 23, 24,
];
// Strides used for flattening `N` dimensional indices.
let src_strides = Strides::new(&[5, 5]);
// Slice function.
let el_fn = |mut index: [Range<usize>; 2]| {
&src[src_strides.flatten_range(index)]
};
// A [3, 3] circular array positioned at `[0, 0]`.
let mut origin = [0, 0];
let mut dst = CircularArray::new([3, 3], vec![
0, 1, 2,
5, 6, 7,
10, 11, 12
]);
// Translate by 2 on axis 0 (Pushes 2 columns to front of axis 0).
let (axis, n) = (0, 2);
dst.translate_front(axis, n, origin, el_fn);
origin[axis] += n as usize;
assert_eq!(dst.iter().cloned().collect::<Vec<usize>>(), &[
2, 3, 4,
7, 8, 9,
12, 13, 14,
]);
// Translate by 1 on axis 1 (Pushes 1 row to front of axis 1).
let (axis, n) = (1, 1);
dst.translate_front(axis, n, origin, el_fn);
origin[axis] += n as usize;
assert_eq!(dst.iter().cloned().collect::<Vec<usize>>(), &[
7, 8, 9,
12, 13, 14,
17, 18, 19,
]);Sourcefn translate_back<'b, F>(
&'a mut self,
axis: usize,
n: usize,
origin: [usize; N],
el_fn: F,
)
fn translate_back<'b, F>( &'a mut self, axis: usize, n: usize, origin: [usize; N], el_fn: F, )
Translate the array by -n on the given axis, inserting elements to the
back of the array.
Requires specifying the array origin of the CircularArray relative to
translation. N dimensional index range ([Range<usize>; N]) will be passed
to the el_fn for slicing a source buffer to retrieve the new elements.
Note that the caler should ensure that a translation of n is within the
source array bounds prior to calling this function.
In the following example, we pre-calculate the [crate::Strides] of
the source array to flatten the N dimensional index into a contiguous
range (requires feature flag strides). Alternatively, the index range can
be passed to 3rd party crates for slicing operations.
// A [5, 5] source array.
let src = [
0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11, 12, 13, 14,
15, 16, 17, 18, 19,
20, 21, 22, 23, 24,
];
// Strides used for flattening `N` dimensional indices.
let src_strides = Strides::new(&[5, 5]);
// Slice function.
let el_fn = |mut index: [Range<usize>; 2]| {
&src[src_strides.flatten_range(index)]
};
// A [3, 3] circular array positioned at `[2, 2]`.
let mut origin = [2, 2];
let mut dst = CircularArray::new([3, 3], vec![
12, 13, 14,
17, 18, 19,
22, 23, 24,
]);
// Translate by -2 on axis 0 (Pushes 2 columns to back of axis 0).
let (axis, n) = (0, 2);
dst.translate_back(axis, n, origin, el_fn);
origin[axis] -= n;
assert_eq!(dst.iter().cloned().collect::<Vec<usize>>(), &[
10, 11, 12,
15, 16, 17,
20, 21, 22,
]);
// Translate by -1 on axis 1 (Pushes 1 row to back of axis 1).
let (axis, n) = (1, 1);
dst.translate_back(axis, n, origin, el_fn);
origin[axis] -= n;
assert_eq!(dst.iter().cloned().collect::<Vec<usize>>(), &[
5, 6, 7,
10, 11, 12,
15, 16, 17,
]);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.