peekable_next 0.2.0

An extension for Rust iterators to peek at the next element without advancing
Documentation
  • Coverage
  • 91.67%
    11 out of 12 items documented8 out of 11 items with examples
  • Size
  • Source code size: 50.55 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 530.11 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • delta1024

peekable_next

Crates.io Docs.rs License: GPL-3.0

The peekable_next crate provides an extension for Rust iterators, introducing the PeekableNext struct and associated traits. This extension allows users to peek at the next element of an iterator without advancing it, which can be valuable in various scenarios where you need to inspect upcoming values before making further decisions.

Usage

Add this crate to your Cargo.toml:

[dependencies]
peekable_next = "0.2.0"

Import the `PeekNext` trait into your code:
```rust
 use peekable_next::PeekNext;

Basic Example

let data = vec![1, 2, 3];
let mut iter = data.iter().peekable_next();

// Peeking allows us to see the next value without advancing the iterator
assert_eq!(iter.peek(), Some(&&1));
assert_eq!(iter.peek_next(), Some(&&2));
assert_eq!(iter.next(), Some(&1)); // Advances to the next element (2)

assert_eq!(iter.peek(), Some(&&2));
assert_eq!(iter.next(), Some(&2)); // Advances to the next element (3)

// After the iterator is finished, peek returns None
assert_eq!(iter.peek(), Some(&&3));
assert_eq!(iter.next(), Some(&2));

Documentation