peeknth
An iterator adapter for peeking multiple elements ahead or behind in a Rust iterator.
✨ Features
- 🔭 Peek N elements ahead (
peek_nth(n)) - 🔁 Peek from both ends with double-ended iterators (
peek_front,peek_back) - 🎯 Range-based peeking (
peek_range(start..end)) - ⚡ Lightweight adapters with feature flags (
peekn,peekdn,peekde) - 📐
SizedPeekN,SizedPeekDn– Zero-allocation, fixed-capacity peek buffers - 🧩 Implements Iterator, so compatible with .map(), .filter(), etc.
🔧 Feature Flags
| Feature | Description |
|---|---|
peekn |
Enables PeekN, SizedPeekN (forward peek types) |
peekdn |
Enables PeekDN, SizedPeekDN (double-ended peek types) |
peekde |
Enables PeekableDE, a lightweight double-ended peek wrapper |
alloc |
Required for types that use dynamic buffers (PeekN, PeekDN, etc.) |
default |
["peekn", "alloc"] |
all |
Enables all features |
You can control features in Cargo.toml like:
= { = "0.3", = ["peekdn"] }
🔒 no_std Compatibility
This crate is 100% #![no_std] compatible.
- Types like
SizedPeekN,SizedPeekDNandPeekableDErequire no allocation and run on bare-metal targets. - Types like
PeekNandPeekDNrequire thealloccrate to support internal buffers (e.g.VecDeque).
To use in strict no_std (no alloc), only use the Sized* types:
= { = "0.2", = false, = ["peekn","peekdn"] }
🚀 Usage
Forward peek (peekn)
use peekn;
let mut iter = peekn;
assert_eq!;
assert_eq!;
Double-ended peek (peekdn)
use peekdn;
let mut iter = peekdn;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Lightweight peek (peekablede)
use peekablede;
let mut iter = peekablede;
assert_eq!;
assert_eq!;
Peek a range
use peekn;
let mut iter = peekn;
let values: = iter.peek_range.cloned.collect;
assert_eq!;
Consume while matching (while_next)
use peekn;
let mut iter = peekn;
let result: = iter.while_next.collect;
assert_eq!;
Fixed-capacity peek (SizedPeekN / SizedPeekDN)
use sizedpeekn;
let mut it = ;
assert_eq!;
use sizedpeekdn;
let mut it = ;
assert_eq!;
📦 Crate Info
- License: MIT OR Apache-2.0
- Crate: peeknth on crates.io
- Docs: docs.rs/peeknth
- Repository: GitHub
#![no_std]compatible- Requires
allocfor heap-backed types (PeekN,PeekDn, etc.) - Fully usable without
alloc:SizedPeekN,SizedPeekDN,PeekableDE
🔖 License
This project is dual-licensed under either:
- MIT
- Apache-2.0
You may choose the license that best suits your needs.