Crate array_util
source ·Expand description
no_std array helpers available without nightly.
Many useful array and slice methods are currently gated by nightly features, though their general functionality and interface is essentially stable. As such this crate provides stable alternatives to the following features, often the same underlying implementation as the current nightly version:
§Usage
Users can either import the SliceExt or ArrayExt traits to bring in the
desired methods, or use the bare methods. Note that trait methods have the
_ext suffix to avoid collision with the core library methods.
use array_util::ArrayExt;
let a = ["1", "2", "3"];
let b = a.try_map_ext(|v| v.parse::<u32>()).unwrap().map(|v| v + 1);
assert_eq!(b, [2, 3, 4]);
let a = ["1", "2a", "3"];
let b = a.try_map_ext(|v| v.parse::<u32>());
assert!(b.is_err());let a = ["1", "2", "3"];
let b = array_util::try_map(a, |v| v.parse::<u32>()).unwrap().map(|v| v + 1);
assert_eq!(b, [2, 3, 4]);
let a = ["1", "2a", "3"];
let b = array_util::try_map(a, |v| v.parse::<u32>());
assert!(b.is_err());Structs§
- An iterator over a slice in (non-overlapping) chunks (
Nelements at a time), starting at the beginning of the slice. - An iterator over a slice in (non-overlapping) mutable chunks (
Nelements at a time), starting at the beginning of the slice.
Traits§
- A helper extension trait for arrays
- A helper extension trait for slices
Functions§
- Returns an iterator over
Nelements of the slice at a time, starting at the beginning of the slice. - Returns an iterator over
Nelements of the slice at a time, starting at the beginning of the slice. - Splits the slice into a slice of
N-element arrays, starting at the beginning of the slice, and a remainder slice with length strictly less thanN. - Splits the slice into a slice of
N-element arrays, starting at the beginning of the slice, and a remainder slice with length strictly less thanN. - Splits the slice into a slice of
N-element arrays, assuming that there’s no remainder. - Splits the slice into a slice of
N-element arrays, assuming that there’s no remainder. - Splits the slice into a slice of
N-element arrays, starting at the end of the slice, and a remainder slice with length strictly less thanN. - Splits the slice into a slice of
N-element arrays, starting at the end of the slice, and a remainder slice with length strictly less thanN. - Creates an array
[T; N]where each fallible array elementTis returned by thecbcall. Unlikefrom_fn, where the element creation can’t fail, this version will return an error if any element creation was unsuccessful. - A fallible function
fapplied to each element on arrayselfin order to return an array the same size asselfor the first error encountered.