← ClaudeAtlas

rust-iterator-impllisted

Use when you write the producing side of iteration for your own type, including a hand-written Iterator impl, the three IntoIterator impls for a container, FromIterator, Extend, size_hint, and an adapter chain that fails on a trait bound. Covers the unconditional_recursion stack overflow from self.into_iter(), why a Deref newtype still gets no for loop and no collect, E0207 on a lending iterator that borrows from itself, the ExactSizeIterator len panic, why enumerate().rev() needs ExactSizeIterator while rev().enumerate() renumbers the indices, and std::iter::from_fn in place of nightly gen blocks. Triggers on "implement Iterator", "custom iterator", "IntoIterator", "into_iter", "FromIterator", "Extend", "size_hint", "ExactSizeIterator", "DoubleEndedIterator", "next_back", "lending iterator", "iter::from_fn", "gen block", "enumerate().rev()", "E0207", or "unconditional_recursion".
po4yka/rust-skills · ★ 2 · AI & Automation · score 76
Install: claude install-skill po4yka/rust-skills
# Rust iterator impl ## Purpose Write the producing side of the iterator protocol: a hand-written `Iterator`, the `IntoIterator` impls a container owes its callers, `FromIterator`, `Extend`, `size_hint`, and the adapter bounds that decide whether a chain compiles. Each rule here fixes a defect that the compiler accepts with a warning, or reports against the wrong line, or moves to run time. This skill stops at the trait impls. Combinator style on the calling side belongs to `rust-code-style`. Iteration cost, once the impls are correct, belongs to `rust-hot-path`. Every error text, warning, and number below comes from rustc 1.97.0, edition 2024, on aarch64-apple-darwin. ## Route the symptom to a section | Symptom or task | Section | | --- | --- | | `error[E0277]: &Bag is not an iterator` on `for v in &bag` | [The three IntoIterator impls](#the-three-intoiterator-impls) | | `warning: function cannot return without recursing`, then `stack overflow` | [Never call self.into_iter() in the impl](#never-call-selfinto_iter-in-the-impl) | | `error[E0277]: a value of type X cannot be built from an iterator` | [A collection newtype needs four impls](#a-collection-newtype-needs-four-impls) | | `error[E0207]: the lifetime parameter 'a is not constrained` | [Iterator cannot borrow from itself](#iterator-cannot-borrow-from-itself) | | A panic inside `core/src/iter/traits/exact_size.rs` | [size_hint is a contract](#size_hint-is-a-contract) | | `error[E0277]: ... ExactSizeIterator is not