{"id":15067629,"url":"https://github.com/weezy20/better_peekable","last_synced_at":"2026-02-18T17:31:07.112Z","repository":{"id":57674312,"uuid":"482590192","full_name":"weezy20/better_peekable","owner":"weezy20","description":"A lightweight iterator adaptor to allow peeking N items ahead using a VecDeque.","archived":false,"fork":false,"pushed_at":"2022-04-29T17:48:25.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-06T05:36:31.107Z","etag":null,"topics":["iterator","lexer","parser","peek","rust","tokenizer"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/better_peekable","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weezy20.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-17T17:32:58.000Z","updated_at":"2025-04-19T07:42:08.000Z","dependencies_parsed_at":"2022-08-31T13:11:33.907Z","dependency_job_id":null,"html_url":"https://github.com/weezy20/better_peekable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weezy20/better_peekable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weezy20%2Fbetter_peekable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weezy20%2Fbetter_peekable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weezy20%2Fbetter_peekable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weezy20%2Fbetter_peekable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weezy20","download_url":"https://codeload.github.com/weezy20/better_peekable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weezy20%2Fbetter_peekable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278948103,"owners_count":26073766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iterator","lexer","parser","peek","rust","tokenizer"],"created_at":"2024-09-25T01:25:21.777Z","updated_at":"2025-10-10T12:05:09.782Z","avatar_url":"https://github.com/weezy20.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Better Peekable\n\nThis crate provides a trait `BetterPeekable` and a type `BPeekable\u003cI: Iterator\u003e` which is a wrapper over an iterator and returned by calling `better_peekable()` on any `Iterator`. You can call the usual iterator methods on `BPeekable\u003cI\u003e` just like `next()` on `I`. You can also call methods like `next_back`,`size_hint` and `rposition` and everything else from `DoubleEndedIterator` in addition to `peek` and `peek_n`. \n\n`peek` gives you a reference to the immediately available item to be consumed by a `next()` call, whereas `peek_n` allows you to peek `n` times ahead. Calling `peek_n(0)` is the same as calling `peek`.\n\n`peek` and `peek_n` are idempotent which means calling them repeatedly on `BPeekable` should have no effects on the underlying iterator or any state of `BPeekable`. If you find a bug that violates this contract, please open an issue.\n\n## Usage\n\nAdd to `better_peekable` to your `Cargo.toml`.\n\n```toml\n[dependencies]\nbetter_peekable = \"0.2.4\"\n```\n\nWe are going to test the idempotence of `BPeekable` using the following sequence of `peek` and `peek_n` calls. \n\n```rust\n// Required for peek and peek_n \nuse better_peekable::BetterPeekable;\n\nfn main() {\n    let vec = vec![\n            String::from(\"Hello\"),\n            String::from(\"World\"),\n            String::from(\"It's a nice day to make\"),\n            String::from(\"A better peekable iterator adaptor\"),\n            String::from(\"Peek_N and Peek are supposed to be\"),\n            String::from(\"Idempotent Methods\"),\n        ];\n\n        let mut iter = vec.into_iter();\n        let mut better_peeker = iter.better_peekable();\n       \n        assert_eq!(better_peeker.peek(), Some(\u0026\"Hello\".to_string()));\n        assert_eq!(better_peeker.peek(), Some(\u0026\"Hello\".to_string()));\n        assert_eq!(better_peeker.peek(), Some(\u0026\"Hello\".to_string()));\n        assert_eq!(better_peeker.peek_n(1), Some(\u0026\"World\".to_string()));\n        assert_eq!(better_peeker.next(), Some(\"Hello\".to_string()));\n        assert_eq!(better_peeker.next(), Some(\"World\".to_string()));\n        assert_eq!(\n            better_peeker.peek(),\n            Some(\u0026\"It's a nice day to make\".to_string())\n        );\n        assert_eq!(\n            better_peeker.peek_n(0),\n            Some(\u0026\"It's a nice day to make\".to_string())\n        );\n        assert_eq!(\n            better_peeker.peek_n(1),\n            Some(\u0026\"A better peekable iterator adaptor\".to_string())\n        );\n        assert_eq!(\n            better_peeker.nth(1),\n            Some(\"A better peekable iterator adaptor\".to_string())\n        );\n        assert_eq!(\n            better_peeker.peek_n(1),\n            Some(\u0026\"Idempotent Methods\".to_string())\n        );\n```\n\n### Changelog 0.2.4 :\nRemoved trait bound `std::fmt::Debug` bound from `Iterator::Item`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweezy20%2Fbetter_peekable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweezy20%2Fbetter_peekable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweezy20%2Fbetter_peekable/lists"}