rust-iterator-impllisted
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