Skip to content
Back to skills

Rust Iterator Collections

ASecurity

Design and review Rust iterator pipelines and collection code for clear ownership, allocation, ordering, and error behavior. Use when writing, refactoring, or reviewing iterators, HashMap Entry usage, collect, FromIterator, Extend, custom iterators, or allocation-heavy loops.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 12, 2026
ai-agentsrustgoexpressdebuggingrefactoringgitapi

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 12, 2026

npx -y skills add thedixitjain/the-mega-skill-library --skill rust-iterator-collections --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rust Iterator Collections?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rust Iterator Collections
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/thedixitjain-rust-iterator-collections/badge)](https://www.skillsdirectory.com/skills/thedixitjain-rust-iterator-collections)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rust-iterator-collections
description: "Design and review Rust iterator pipelines and collection code for clear ownership, allocation, ordering, and error behavior. Use when writing, refactoring, or reviewing iterators, HashMap Entry usage, collect, FromIterator, Extend, custom iterators, or allocation-heavy loops."
category: engineering-core
source_repo: hashgraph-online/awesome-codex-plugins
source_path: "plugins/LVTD-LLC/skills/skills/rust-iterator-collections/SKILL.md"
source_url: https://github.com/hashgraph-online/awesome-codex-plugins/blob/HEAD/plugins/LVTD-LLC/skills/skills/rust-iterator-collections/SKILL.md
---


# Rust Iterator Collections

Use this skill to turn collection code into clear, idiomatic Rust. Prefer
iterator and collection APIs that express the operation directly while keeping
ownership, allocation, and error behavior visible.

## Core Workflow

1. Identify the input ownership mode: borrowed iteration, mutable iteration, or
   consuming iteration.
2. Pick the simplest iterator shape: `iter`, `iter_mut`, `into_iter`, ranges,
   `drain`, or a collection-specific method.
3. Replace manual loops with adapters only when the resulting code is clearer.
   Keep explicit loops for complex branching, early mutation, or debugging.
4. Use fallible iterator consumers such as `collect::<Result<Vec<_>, _>>()`,
   `try_fold`, and `try_for_each` when errors should short-circuit.
5. Use `HashMap::entry` or `BTreeMap::entry` for insert-or-update logic.
6. Avoid unnecessary intermediate `Vec`s. Chain iterators or extend an existing
   collection when possible.
7. Test empty input, single item input, duplicate keys, ordering expectations,
   and error short-circuiting.

## Iterator Rules

- Accept `impl IntoIterator<Item = T>` when the function only needs iteration.
- Use `&[T]` when slice semantics are enough; avoid `&Vec<T>`.
- Use `filter_map` for map-then-discard-`None`; use `flat_map` when each item
  expands to zero or more items.
- Use `map_while` or `scan` for stateful transformations when they make stopping
  behavior explicit.
- Add type annotations at `collect` boundaries, not throughout the pipeline.
- Prefer `cloned` or `copied` over `map(|x| x.clone())` when cloning iterator
  items is intentional.

## Collection Rules

Read `references/iterator-collection-patterns.md` when refactoring a loop or
reviewing collection mutation.

- Use `Vec` for contiguous ordered data, `VecDeque` for queue-like push/pop at
  both ends, `BinaryHeap` for priority queues, `HashMap` for unordered lookup,
  and `BTreeMap` for sorted lookup or range queries.
- Use `retain`, `drain`, `splice`, and `split_off` instead of mutating a
  collection while separately iterating over borrowed elements.
- Use `Entry::or_insert_with` when default construction is expensive.
- Preserve ordering deliberately. Do not swap `BTreeMap` for `HashMap` when
  iteration order is part of behavior.
- Reserve capacity only when size is known or profiling shows reallocation
  matters.

## Review Checklist

- The pipeline communicates ownership and error behavior clearly.
- No `contains_key` followed by `insert` where `entry` would be simpler.
- No avoidable `collect::<Vec<_>>()` just to iterate again.
- Indexing is used only when indices are the domain concept.
- Tests cover duplicates, empty input, and deterministic ordering where needed.

---

**Source:** [`hashgraph-online/awesome-codex-plugins`](https://github.com/hashgraph-online/awesome-codex-plugins) → `plugins/LVTD-LLC/skills/skills/rust-iterator-collections/SKILL.md`

Files in this skill

  • SKILL.md3.5 KB
  • agents/openai.yaml229 B
  • references/iterator-collection-patterns.md1.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.