pub trait ArrayTools<T, const N: usize> {
Show 13 methods
// Required methods
fn skip<const BY: usize>(self) -> [T; { _ }];
fn step<const STEP: usize>(self) -> [T; { _ }];
fn intersperse(self, with: T) -> [T; { _ }]
where T: Clone;
fn each(self, apply: impl FnMut(T));
fn enumerate(self) -> [(T, usize); N];
fn windowed<const W: usize>(&self) -> [&[T; W]; { _ }];
fn inspect(self, f: impl FnMut(&T)) -> Self;
fn rev(self) -> Self;
fn interleave(self, with: [T; N]) -> [T; { _ }];
fn cartesian_product<U: Clone, const M: usize>(
self,
with: &[U; M],
) -> [(T, U); { _ }]
where T: Clone;
fn sort(self) -> Self
where T: Ord;
fn sum(self) -> T
where T: Sum<T>;
fn product(self) -> T
where T: Product<T>;
}Expand description
Array tools.
Required Methods§
Sourcefn skip<const BY: usize>(self) -> [T; { _ }]
fn skip<const BY: usize>(self) -> [T; { _ }]
Skip BY elements.
Sourcefn step<const STEP: usize>(self) -> [T; { _ }]
fn step<const STEP: usize>(self) -> [T; { _ }]
Skip every BY elements.
let x = range::<5>().step::<2>();
assert_eq!(x, [0, 2, 4]);
let x = range::<20>().step::<5>();
assert_eq!(x, [0, 5, 10, 15]);
assert_eq!(range::<50>().step::<3>(), [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]);Sourcefn intersperse(self, with: T) -> [T; { _ }]where
T: Clone,
fn intersperse(self, with: T) -> [T; { _ }]where
T: Clone,
Intersperse a element in between items.
let x = range::<3>().intersperse(5);
assert_eq!(x, [0, 5, 1, 5, 2]);Sourcefn windowed<const W: usize>(&self) -> [&[T; W]; { _ }]
fn windowed<const W: usize>(&self) -> [&[T; W]; { _ }]
Get the sliding windows of this array.
assert_eq!(range::<5>().windowed::<2>(), [&[0, 1], &[1, 2], &[2, 3], &[3, 4]]);Sourcefn interleave(self, with: [T; N]) -> [T; { _ }]
fn interleave(self, with: [T; N]) -> [T; { _ }]
Interleave items from two arrays.
assert_eq!([0u8, 2, 4].interleave([1, 3, 5]), [0, 1, 2, 3, 4, 5]);Sourcefn cartesian_product<U: Clone, const M: usize>(
self,
with: &[U; M],
) -> [(T, U); { _ }]where
T: Clone,
fn cartesian_product<U: Clone, const M: usize>(
self,
with: &[U; M],
) -> [(T, U); { _ }]where
T: Clone,
Cartesian product (A × B) of two arrays.
assert_eq!([1u64, 2].cartesian_product(&["Π", "Σ"]), [(1, "Π"), (1, "Σ"), (2, "Π"), (2, "Σ")]);Sourcefn sort(self) -> Selfwhere
T: Ord,
fn sort(self) -> Selfwhere
T: Ord,
Sorts it. This uses [T]::sort_unstable.
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.