9 releases

0.3.1 Oct 31, 2021
0.3.0 Sep 9, 2021
0.2.2 Jul 30, 2021
0.2.1 May 26, 2021
0.1.3 Apr 21, 2021

#1199 in Rust patterns

Download history 126/week @ 2023-12-15 108/week @ 2023-12-22 66/week @ 2023-12-29 131/week @ 2024-01-05 208/week @ 2024-01-12 195/week @ 2024-01-19 162/week @ 2024-01-26 135/week @ 2024-02-02 102/week @ 2024-02-09 215/week @ 2024-02-16 133/week @ 2024-02-23 140/week @ 2024-03-01 171/week @ 2024-03-08 240/week @ 2024-03-15 246/week @ 2024-03-22 279/week @ 2024-03-29

947 downloads per month
Used in 6 crates (2 directly)

MIT/Apache

21KB
246 lines

iter_fixed

crates.io docs.rs dependency status

Stable Nightly Miri

This project is inspired by @leonardo-m 's idea https://github.com/rust-lang/rust/issues/80094#issuecomment-749260428

**This code is currently very experimental, type names, function names, trait bounds etc. are all very much subject to change.

Provides a type and traits for turning collections of fixed size, like arrays, into IteratorFixed which can be used a bit like an ordinary Iterator but with a compile time guaranteed length. This enables us to turn them back into collections of fixed size without having to perform unnecessary checks during run time.

Just like Iterator, IteratorFixed provides methods like:

Works on stable rust
Requires nightly compiler

however it does not and will never be able to support methods like filter or take_while which will affect the length during runtime.

no_std

This crate should work without the full standard library

Examples

Toy example

// zip together two arrays of length 4, turn the elements wise sums of the
// two middle elements into an array of size 2
let res: [_; 2] = [1, 2, 3, 4]
    .into_iter_fixed()
    .zip([4, 3, 2, 1])
    .map(|(a, b)| a + b)
    .skip::<1>()
    .take::<2>()
    .collect();

assert_eq!(res, [5, 5]);

Vector

see examples/vector.rs

Matrix

see examples/matrix.rs

License

iter_fixed is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, and LICENSE-MIT for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in iter_fixed by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Features