Expand description
Generally helpful utility functions and traits.
This crate provides three groups of utilities:
Array: a trait implemented for everyAsRef<[T]>type that offers JavaScript-inspired array methods (map,filter,find,reduce,join, and many more), along with binary-search-based*_equal_in_sorted_bymethods for sorted slices.subarray,subarray_checked, andsubarray_unchecked: functions returning a fixed-size array reference&[T; S]into a slice.ToResultandResConv: ergonomic conversions forResultandOptionvalues.
§Examples
use ps_util::{Array, ToResult};
let arr = [1, 2, 3, 4];
assert_eq!(arr.filter(|x| x % 2 == 0), vec![2, 4]);
assert_eq!(arr.join(" + "), "1 + 2 + 3 + 4");
assert_eq!(arr.find_index_equal_in_sorted_by(|x| x.cmp(&3)), Some(2));
assert_eq!(7.ok::<()>(), Ok(7));Traits§
- Array
- ResConv
- Conversions between
ResultandOptionwith optional value transformation. - ToResult
- Convenience constructors for
ResultandOptionvalues.
Functions§
- subarray
- Get a subarray of length
Satindex. - subarray_
checked - Returns a reference to a contiguous subarray of length
Sstarting atindex. - subarray_
unchecked ⚠ - Get a subarray of length
Satindexwithout bounds checking.