Michael Buesch 5c7e157254 Update release script | 1 ヶ月 前 | |
---|---|---|
.github | 1 ヶ月 前 | |
maintenance | 1 ヶ月 前 | |
src | 6 ヶ月 前 | |
.gitignore | 1 ヶ月 前 | |
Cargo.lock | 1 ヶ月 前 | |
Cargo.toml | 1 ヶ月 前 | |
LICENSE-APACHE | 6 ヶ月 前 | |
LICENSE-MIT | 6 ヶ月 前 | |
README.md | 6 ヶ月 前 |
This is an Iterator Peekable similar to std::iter::Peekable
, but with additional features:
This crate is #![no_std]
, does not heap-allocate and does not contain unsafe
code.
The wrapped Iterator::Item
must implement Clone
.
use peekable_fwd_bwd::Peekable;
use core::slice::Iter;
let array = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25];
const BWD_SIZE: usize = 2; // size of backward peek buffer.
const FWD_SIZE: usize = 8; // size of forward peek buffer.
let mut iter = Peekable::<Iter<i32>, BWD_SIZE, FWD_SIZE>::new(&array);
assert_eq!(iter.next(), Some(&10));
assert_eq!(iter.next(), Some(&11));
// forward peek into the future.
assert_eq!(iter.peek(), Some(&&12));
assert_eq!(iter.peek_nth(0), Some(&&12));
assert_eq!(iter.peek_nth(1), Some(&&13));
assert_eq!(iter.peek_nth(8), None); // FWD_SIZE too small.
assert_eq!(iter.next(), Some(&12));
// backward peek into the past.
assert_eq!(iter.peek_bwd(), Some(&&12));
assert_eq!(iter.peek_bwd_nth(0), Some(&&12));
assert_eq!(iter.peek_bwd_nth(1), Some(&&11));
assert_eq!(iter.peek_bwd_nth(2), None); // BWD_SIZE too small.
#![no_std]
. It does not allocate.std
.Copyright (c) 2024 Michael Büsch m@bues.ch
Licensed under the Apache License version 2.0 or the MIT license, at your option.