https://github.com/foresterre/peekmore
👀 Multi-peek iterator (no-std)
https://github.com/foresterre/peekmore
hacktoberfest iterator iterator-library multi-peek multipeek peek peek-ahead rust rust-library
Last synced: about 2 months ago
JSON representation
👀 Multi-peek iterator (no-std)
- Host: GitHub
- URL: https://github.com/foresterre/peekmore
- Owner: foresterre
- License: apache-2.0
- Created: 2019-09-09T18:34:43.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-10T22:33:02.000Z (6 months ago)
- Last Synced: 2025-03-28T19:08:47.072Z (about 2 months ago)
- Topics: hacktoberfest, iterator, iterator-library, multi-peek, multipeek, peek, peek-ahead, rust, rust-library
- Language: Rust
- Homepage: https://docs.rs/peekmore
- Size: 108 KB
- Stars: 26
- Watchers: 2
- Forks: 7
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# peekmore
This crate introduces a multi-peekable iterator.
The iterator is similar to [core::iterator::Peekable](https://doc.rust-lang.org/core/iter/struct.Peekable.html).
The main difference is that Peekable only allows you to peek at the next element and no further.
This crate aims to take that limitation away.The documentation and more extensive example usage can be found at [docs.rs/peekmore](https://docs.rs/peekmore/).
### Usage example:
```rust
use peekmore::PeekMore;fn main() {
let range10 = 0..11;
let mut peekable = range10.peekmore();
// Peek at the first element
let peek_first = peekable.peek();
assert_eq!(*peek_first.unwrap(), 0);
let peek_first_redux = peekable.peek_nth(0);
assert_eq!(*peek_first_redux.unwrap(), 0);
// Peek at the 10th (index) element
let peek_tenth = peekable.peek_nth(10);
assert_eq!(*peek_tenth.unwrap(), 10);
// Consume the 10th element
let tenth = peekable.nth(10);
assert_eq!(tenth.unwrap(), 10);
// Show that there are no more elements
assert_eq!(peekable.peek(), None);
assert_eq!(peekable.next(), None);
}```
### License
Licensed under either of* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.
#### Contribution
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.