10 releases

0.4.0 Jun 23, 2024
0.3.1 Oct 31, 2021
0.3.0 Sep 9, 2021
0.2.2 Jul 30, 2021
0.1.3 Apr 21, 2021

#659 in Rust patterns

Download history 144/week @ 2024-07-22 177/week @ 2024-07-29 244/week @ 2024-08-05 84/week @ 2024-08-12 80/week @ 2024-08-19 80/week @ 2024-08-26 45/week @ 2024-09-02 64/week @ 2024-09-09 75/week @ 2024-09-16 107/week @ 2024-09-23 85/week @ 2024-09-30 47/week @ 2024-10-07 48/week @ 2024-10-14 38/week @ 2024-10-21 44/week @ 2024-10-28 42/week @ 2024-11-04

175 downloads per month
Used in 6 crates (3 directly)

MIT/Apache

24KB
285 lines

Maintenance

crates.io docs.rs dependency status

Stable Nightly Miri

iter_fixed

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.

IteratorFixed provides on stable methods like map, inspect, enumerate, zip, rev, copied, cloned, with nightly skip, step_by, chain, take, flatten.

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

⚠️ Experimental

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

Origin

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

Examples:

// simply reverse an Array
let rev_array: [_; 4] = [1, 3, 2, 7]
    .into_iter_fixed()
    .rev()
    .collect();
assert_eq!(rev_array, [7, 2, 3, 1]);

// .. and compute sum with values of a second array multiplied by 10
let sum_array: [_; 4] = rev_array
    .into_iter_fixed()
    .zip([4,1,3,7])
    .map(|(a, b)| a + (b * 10))
    .collect();
assert_eq!(sum_array, [47, 12, 33, 71]);

You can also take a look at examples : matrix.rs and vector.rs

Current version: 0.4.0

no_std

This crate should work without the full standard library

Some additional info here

License : MIT OR Apache-2.0

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