Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brendanashworth/peepable
A Rust look-alike for Peekable that allows peeping into immutable references.
https://github.com/brendanashworth/peepable
iterator peek rust
Last synced: 9 days ago
JSON representation
A Rust look-alike for Peekable that allows peeping into immutable references.
- Host: GitHub
- URL: https://github.com/brendanashworth/peepable
- Owner: brendanashworth
- License: mit
- Created: 2017-08-18T20:07:05.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-18T22:00:56.000Z (about 7 years ago)
- Last Synced: 2024-10-12T20:36:53.444Z (about 1 month ago)
- Topics: iterator, peek, rust
- Language: Rust
- Homepage: https://crates.io/crates/peepable
- Size: 4.88 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# peepable
[![Crates.io](https://img.shields.io/crates/v/peepable.svg)](https://crates.io/crates/peepable) [![Build Status](https://travis-ci.org/brendanashworth/peepable.svg?branch=master)](https://travis-ci.org/brendanashworth/peepable) [![docs.rs](https://docs.rs/peepable/badge.svg)](https://docs.rs/peepable)
peepable is a Rust look-alike for [`Peekable`](https://doc.rust-lang.org/std/iter/struct.Peekable.html).
It behaves slightly different as it eagerly loads the next value in the Iterator.
This allows `.peep()` to be called on an immutable reference, saving you from the
borrow checker.## Example
```rust
use std::iter::Iterator;
use peepable::Peepable;let mut iter = vec![1, 2, 3].into_iter();
// Note, this is not "mut peeper"!
let peeper = Peepable::new(iter);assert_eq!(peeper.peep(), Some(&1));
// When mutable, we can use it as a normal iterator.
let mut peeper = peeper;assert_eq!(peeper.next(), Some(1));
assert_eq!(peeper.peep(), Some(&2));
assert_eq!(peeper.next(), Some(2));assert_eq!(peeper.next(), Some(3));
assert_eq!(peeper.peep(), None);
assert_eq!(peeper.next(), None);
```## License
peepable is licensed under the [MIT license](./LICENSE).