rust-iterator-impl

Implements Iterator, IntoIterator, FromIterator, and Extend traits for custom Rust types.

2|1|Updated Aug 19, 2026
One-click install
npx skills add https://github.com/po4yka/rust-skills --skill rust-iterator-impl-po4yka
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-iterator-impl
Source: https://github.com/po4yka/rust-skills/tree/main/skills/rust-iterator-impl
Command: npx skills add https://github.com/po4yka/rust-skills --skill rust-iterator-impl-po4yka

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing custom iterators or making a custom Rust type iterable triggers a cluster of confusing compiler errors and runtime traps: E0277 when a for loop rejects a container, E0207 on lending iterators, stack overflows from recursive into_iter bodies, and ExactSizeIterator len panics from a missing size_hint override. This Skill maps each symptom to the correct fix with tested code and lint configuration. ## Core Features & Use Cases - Symptom-to-fix routing table: Maps exact rustc 1.98.1 error codes (E0277, E0658, E0207, E0432) and warnings like unconditional_recursion to the section that resolves them. - Complete trait implementation patterns: Provides tested implementations of the three IntoIterator impls, FromIterator, Extend, DoubleEndedIterator, ExactSizeIterator, and size_hint contracts for collection newtypes. - Lending iterator and generator guidance: Shows three compiling shapes for iterators that borrow from themselves, plus stable iter::from_fn, successors, and repeat_with replacements for nightly gen blocks. - Use Case: You write for v in &bag and get error[E0277]: &Bag is not an iterator. The Skill routes you to the three IntoIterator impls section, gives you the full working code, and the clippy lint levels to prevent regressions. ## Quick Start Ask the agent to make your custom collection type iterable in Rust using the rust-iterator-impl skill, or paste the compiler error you hit while implementing Iterator.

Frequently Asked Questions about rust-iterator-impl

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a custom Rust type work in a for loop?▼

Implement IntoIterator for the type itself, for &T, and for &mut T when mutable access is offered. An inherent iter() method alone fails at the for loop call site with error E0277 because the loop resolves through the trait, not method syntax.

How to implement Iterator for a struct in Rust?▼

Define an associated Item type and a next method returning Option<Item>. Forward size_hint from the inner iterator and re-implement DoubleEndedIterator, ExactSizeIterator, and FusedIterator when the inner iterator has them, or collect loses capacity hints.

Why does ExactSizeIterator len panic at runtime?▼

The default len() asserts that size_hint returns an exact (n, Some(n)) pair. Implementing ExactSizeIterator without overriding size_hint compiles cleanly but panics on the first len() call, so always override size_hint first.

Can a Rust iterator yield references into data it owns?▼

No, because Item is an associated type that cannot name the lifetime of &mut self, producing error E0207. Borrow the data instead, yield a guard like Ref<'a, T>, or drop the Iterator impl and expose an inherent method such as next_frame.

Why does enumerate().rev() fail with an ExactSizeIterator error?▼

Enumerate implements DoubleEndedIterator only when the inner iterator is ExactSizeIterator, and adapters like filter, flat_map, chars, or chain lose the exact length. The error blames .rev() even though the earlier adapter broke the bound.

What replaces nightly gen blocks on stable Rust?▼

Use std::iter::from_fn with a move closure that owns the state, returning impl Iterator with no allocation or Pin. For sequences where each item derives from the previous one, use std::iter::successors or std::iter::repeat_with.