3 stable releases

1.0.2 May 23, 2024
1.0.1 Apr 20, 2024
1.0.0 Apr 19, 2024

#71 in No standard library

Download history 1662/week @ 2024-08-17 948/week @ 2024-08-24 1295/week @ 2024-08-31 1261/week @ 2024-09-07 1397/week @ 2024-09-14 2259/week @ 2024-09-21 1563/week @ 2024-09-28 5062/week @ 2024-10-05 5730/week @ 2024-10-12 5710/week @ 2024-10-19 6764/week @ 2024-10-26 7729/week @ 2024-11-02 7247/week @ 2024-11-09 6772/week @ 2024-11-16 7031/week @ 2024-11-23 14054/week @ 2024-11-30

36,345 downloads per month
Used in 5 crates (via foyer-storage)

MIT license

56KB
489 lines

array-util

no_std array helpers available without nightly.

Description

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 an Ext trait (SliceExt, ArrayExt, or SliceOfArrayExt) traits to bring in the desired methods, or use the bare functions. 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());

Limitations

These functions aren't stabilized because they rely on undecided behaviors. For example, "should compile-time errors be generated for 0 length arrays?" or "What should the associated types and traits of Try be?". As these questions remain unresolved, reliance on the particular answers this crate has chosen in it's implementation may make porting to the eventual stabilized version more painful. If you're just calling functions, you'll probably be fine, but try to avoid using the Ext traits as bounds.

License: MIT

Dependencies

~69KB