#array #no-std #methods #fixed-size #helpful #variety #tuple

no-std arraytools

A variety of helpful methods for working with fixed-size arrays

6 releases

0.1.5 Feb 23, 2019
0.1.4 Feb 22, 2019

#2901 in Rust patterns

Download history 252/week @ 2024-01-01 526/week @ 2024-01-08 1023/week @ 2024-01-15 1372/week @ 2024-01-22 497/week @ 2024-01-29 773/week @ 2024-02-05 551/week @ 2024-02-12 659/week @ 2024-02-19 979/week @ 2024-02-26 989/week @ 2024-03-04 785/week @ 2024-03-11 800/week @ 2024-03-18 974/week @ 2024-03-25 360/week @ 2024-04-01 329/week @ 2024-04-08 1280/week @ 2024-04-15

2,955 downloads per month

MIT/Apache

28KB
331 lines

arraytools

A variety of helpful methods for working with fixed-size arrays.

docs.rs-hosted documentation travis build status

Examples

Iterator-like methods over arrays:

use arraytools::ArrayTools;

assert_eq!([1, 2, 3].map(|x| x+1), [2, 3, 4]);
assert_eq!([1, 2].zip(["one", "two"]), [(1, "one"), (2, "two")]);

Ways to simplify array creation:

use arraytools::ArrayTools;

let mut state = 1;
assert_eq!(<[_; 4]>::generate(|| { state *= 2; state }), [2, 4, 8, 16]);
assert_eq!(<[usize; 4]>::indices(), [0, 1, 2, 3]);

let s = "hello".to_string(); // Something `!Copy`
assert_eq!(<[String; 3]>::repeat(s).as_ref_array(), ["hello", "hello", "hello"]);

Conversion to and from homogeneous tuples:

use arraytools::ArrayTools;

let mut array = [2, 3, 5, 7, 11];
assert_eq!(array.into_tuple(), (2, 3, 5, 7, 11));
array = ArrayTools::from_tuple((1, 1, 2, 3, 5));
assert_eq!(array, [1, 1, 2, 3, 5]);

Usage

How to use with cargo:

[dependencies]
arraytools = "0.1"

How to use in your 2018-edition crate:

use arraytools::ArrayTools;

Because this needs non-Copy slice patterns, it needs at least Rust 1.31.0.

No runtime deps