Crates.io | peepable |
lib.rs | peepable |
version | 0.1.1 |
source | src |
created_at | 2017-08-18 20:57:16.440168 |
updated_at | 2017-08-18 20:57:16.440168 |
description | Peepable is a Peekable that allows peeping into immutable references |
homepage | |
repository | https://github.com/brendanashworth/peepable |
max_upload_size | |
id | 28060 |
size | 9,583 |
peepable is a Rust look-alike for Peekable
.
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.
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);
peepable is licensed under the MIT license.