Trait array__ops::SliceOps
source · pub trait SliceOps<T>: Slice<Item = T> {
Show 30 methods
// Required methods
fn differentiate(&mut self)
where T: SubAssign + Copy;
fn integrate(&mut self)
where T: AddAssign + Copy;
fn argmax(&self) -> Option<usize>
where T: PartialOrd;
fn argmin(&self) -> Option<usize>
where T: PartialOrd;
fn add_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: AddAssign<Rhs>,
Rhs: Copy;
fn sub_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: SubAssign<Rhs>,
Rhs: Copy;
fn mul_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: MulAssign<Rhs>,
Rhs: Copy;
fn div_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: DivAssign<Rhs>,
Rhs: Copy;
fn rem_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: RemAssign<Rhs>,
Rhs: Copy;
fn shl_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: ShlAssign<Rhs>,
Rhs: Copy;
fn shr_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: ShrAssign<Rhs>,
Rhs: Copy;
fn bitor_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: BitOrAssign<Rhs>,
Rhs: Copy;
fn bitand_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: BitAndAssign<Rhs>,
Rhs: Copy;
fn bitxor_assign_all<Rhs>(&mut self, rhs: Rhs)
where T: BitXorAssign<Rhs>,
Rhs: Copy;
fn neg_assign_all(&mut self)
where T: Neg<Output = T>;
fn shift_many_left(&mut self, items: &mut [T]);
fn shift_many_right(&mut self, items: &mut [T]);
fn shift_left(&mut self, item: &mut T);
fn shift_right(&mut self, item: &mut T);
fn split_len(&self, mid: usize) -> (usize, usize);
fn rsplit_len(&self, mid: usize) -> (usize, usize);
fn rsplit_at(&self, mid: usize) -> (&[T], &[T]);
fn rsplit_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]);
fn split_array_ref2<const N: usize>(&self) -> (&[T; N], &[T]);
fn split_array_mut2<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]);
fn rsplit_array_ref2<const N: usize>(&self) -> (&[T], &[T; N]);
fn rsplit_array_mut2<const N: usize>(&mut self) -> (&mut [T], &mut [T; N]);
fn spread_ref<const M: usize>(&self) -> [&[Padded<T, M>]; M];
fn spread_mut<const M: usize>(&mut self) -> [&mut [Padded<T, M>]; M];
fn bit_reverse_permutation(&mut self);
}
Required Methods§
fn differentiate(&mut self)
fn integrate(&mut self)
fn argmax(&self) -> Option<usize>where
T: PartialOrd,
fn argmin(&self) -> Option<usize>where
T: PartialOrd,
fn add_assign_all<Rhs>(&mut self, rhs: Rhs)
fn sub_assign_all<Rhs>(&mut self, rhs: Rhs)
fn mul_assign_all<Rhs>(&mut self, rhs: Rhs)
fn div_assign_all<Rhs>(&mut self, rhs: Rhs)
fn rem_assign_all<Rhs>(&mut self, rhs: Rhs)
fn shl_assign_all<Rhs>(&mut self, rhs: Rhs)
fn shr_assign_all<Rhs>(&mut self, rhs: Rhs)
fn bitor_assign_all<Rhs>(&mut self, rhs: Rhs)where
T: BitOrAssign<Rhs>,
Rhs: Copy,
fn bitand_assign_all<Rhs>(&mut self, rhs: Rhs)where
T: BitAndAssign<Rhs>,
Rhs: Copy,
fn bitxor_assign_all<Rhs>(&mut self, rhs: Rhs)where
T: BitXorAssign<Rhs>,
Rhs: Copy,
fn neg_assign_all(&mut self)where
T: Neg<Output = T>,
fn shift_many_left(&mut self, items: &mut [T])
fn shift_many_right(&mut self, items: &mut [T])
fn shift_left(&mut self, item: &mut T)
fn shift_right(&mut self, item: &mut T)
fn split_len(&self, mid: usize) -> (usize, usize)
fn rsplit_len(&self, mid: usize) -> (usize, usize)
fn rsplit_at(&self, mid: usize) -> (&[T], &[T])
fn rsplit_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T])
sourcefn split_array_ref2<const N: usize>(&self) -> (&[T; N], &[T])
fn split_array_ref2<const N: usize>(&self) -> (&[T; N], &[T])
Does the exact same as the method in the standard library in an identical way, but can be done at compile-time.
Divides one slice into an array and a remainder slice at an index.
The array will contain all indices from [0, N)
(excluding
the index N
itself) and the slice will contain all
indices from [N, len)
(excluding the index len
itself).
§Panics
Panics if N > len
.
§Examples
#![feature(split_array)]
#![feature(const_slice_index)]
const V: [u8; 6] = [1, 2, 3, 4, 5, 6];
{
const SPLIT: (&[u8; 0], &[u8]) = slice_ops::split_array_ref(V.as_slice());
assert_eq!(SPLIT.0, &[]);
assert_eq!(SPLIT.1, [1, 2, 3, 4, 5, 6]);
assert_eq!(SPLIT, V.split_array_ref::<0>());
}
{
const SPLIT: (&[u8; 2], &[u8]) = slice_ops::split_array_ref(V.as_slice());
assert_eq!(SPLIT.0, &[1, 2]);
assert_eq!(SPLIT.1, [3, 4, 5, 6]);
assert_eq!(SPLIT, V.split_array_ref::<2>());
}
{
const SPLIT: (&[u8; 6], &[u8]) = slice_ops::split_array_ref(V.as_slice());
assert_eq!(SPLIT.0, &[1, 2, 3, 4, 5, 6]);
assert_eq!(SPLIT.1, []);
assert_eq!(SPLIT, V.split_array_ref::<6>());
}
fn split_array_mut2<const N: usize>(&mut self) -> (&mut [T; N], &mut [T])
fn rsplit_array_ref2<const N: usize>(&self) -> (&[T], &[T; N])
fn rsplit_array_mut2<const N: usize>(&mut self) -> (&mut [T], &mut [T; N])
sourcefn spread_ref<const M: usize>(&self) -> [&[Padded<T, M>]; M]
fn spread_ref<const M: usize>(&self) -> [&[Padded<T, M>]; M]
Spreads elements equally across M
slices.
Slices will have equal length only if the operand slice’s length is divisible by M
.
§Examples
Take, for instance, that we want to divide a slice into odd and even elements:
use slice_ops::SliceOps;
let arr = [1, 2, 3];
let slice = arr.as_slice();
let [odd, even] = slice.spread_ref();
assert_eq!(odd, [1, 3]);
assert_eq!(even, [2]);
sourcefn spread_mut<const M: usize>(&mut self) -> [&mut [Padded<T, M>]; M]
fn spread_mut<const M: usize>(&mut self) -> [&mut [Padded<T, M>]; M]
Spreads elements equally across M
mutable slices.
Slices will have equal length only if the operand slice’s length is divisible by M
.
§Examples
#![feature(generic_const_exprs)]
use slice_ops::SliceOps;
let mut arr = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"];
let slice = arr.as_mut_slice();
let [_, _, fizz] = slice.spread_mut();
assert_eq!(fizz, ["3", "6", "9", "12", "15"]);
for fizz in fizz.iter_mut()
{
**fizz = "fizz";
}
let [_, _, _, _, buzz] = slice.spread_mut();
assert_eq!(buzz, ["5", "10", "fizz"]);
for buzz in buzz.iter_mut()
{
if **buzz == "fizz"
{
**buzz = "fizzbuzz";
continue;
}
**buzz = "buzz";
}
assert_eq!(arr, ["1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13", "14", "fizzbuzz"]);
sourcefn bit_reverse_permutation(&mut self)
fn bit_reverse_permutation(&mut self)
Performs the bit-reverse permutation. Length must be a power of 2.
§Example
use slice_ops::*;
let mut arr = [0b000, 0b001, 0b010, 0b011, 0b100, 0b101, 0b110, 0b111];
arr.as_mut_slice().bit_reverse_permutation();
assert_eq!(arr, [0b000, 0b100, 0b010, 0b110, 0b001, 0b101, 0b011, 0b111])