5 releases
0.1.4 | Jul 15, 2022 |
---|---|
0.1.3 | Apr 20, 2022 |
0.1.2 | Apr 19, 2022 |
0.1.1 | Apr 19, 2022 |
0.1.0 | Apr 18, 2022 |
#2151 in Rust patterns
13KB
203 lines
eternal_iterator
This Rust crate provides EternalIterator trait, which promises that the iterator iterates forever.
let mut it = core::iter::repeat(123_i32).map(|i| i * 2)
.enumerate().skip(5).step_by(2).zip(core::iter::once(3).chain(10..));
assert_eq!(it.next_eternal(), ((5, 246), 3));
assert_eq!(it.next_eternal(), ((7, 246), 10));
assert_eq!(it.next(), Some(((9, 246), 11)));
assert_eq!(it.next_eternal(), ((11, 246), 12));
generating fixed-size array
You can initialize arbitrary fixed-size array with eternal_iterator.
use eternal_iterator::prelude::*;
let arr: [i32; 5] = (0..).next_array();
assert_eq!(arr, [0, 1, 2, 3, 4]);