Crates.io | array-util |
lib.rs | array-util |
version | 1.0.2 |
source | src |
created_at | 2024-04-19 20:13:40.1699 |
updated_at | 2024-05-23 20:54:20.137821 |
description | no_std array helpers available without nightly |
homepage | |
repository | https://github.com/Daniel-Aaron-Bloom/array-util |
max_upload_size | |
id | 1214079 |
size | 56,871 |
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:
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());
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