Skip to content

Releases: weezy20/better_peekable

v1.0.0

28 Oct 12:56

Choose a tag to compare

Release Notes - v1.0.0

Introduction

Better Peekable is a no_std compatible iterator adapter that provides multi-item lookahead functionality, designed for lexers, parsers, and other applications requiring efficient iterator peeking.

Features

  • Multi-item lookahead with peek_n(n) method
  • Standard peek() method equivalent to peek_n(0)
  • Idempotent peeking operations that don't affect iterator state
  • Full iterator trait support including DoubleEndedIterator and ExactSizeIterator
  • no_std compatibility with alloc feature
  • Efficient internal caching: peek_n(n) will cache n items into the internal VecDeque so subsequent peek_n(m) where m <= n are blazing fast lookups. So if you're going to do a lot of peeking, might as well peek in large numbers and then do short peeks.

API

  • BetterPeekable trait extending all iterators
  • BPeekable struct providing the lookahead functionality
  • peek() - peek at next item
  • peek_n(n) - peek n items ahead (0-indexed)
  • init(iter) - convenience function for creating peekable iterators

Compatibility

Requires alloc feature for VecDeque support
Default features include alloc for standard usage
no_std environments are supported but would require the alloc feature to be enabled as VecDeque requires that for allocation.