rust-iterator-collections
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.
- License 许可
- MIT
- 最近更新
- 2026-06-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- rust-iterator-collections
- license
- MIT
- metadata
- { "tags": "rust,iterators,collections,hashmap,performance", "version": "0.1.0", "category": "Rust", "displayName": "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.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 2
- 参考文档agents/openai.yaml229 B
- 参考文档references/iterator-collection-patterns.md1.7 KB
03 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
- Identify the input ownership mode: borrowed iteration, mutable iteration, or consuming iteration.
- Pick the simplest iterator shape:
iter,iter_mut,into_iter, ranges,drain, or a collection-specific method. - Replace manual loops with adapters only when the resulting code is clearer. Keep explicit loops for complex branching, early mutation, or debugging.
- Use fallible iterator consumers such as
collect::<Result<Vec<_>, _>>(),try_fold, andtry_for_eachwhen errors should short-circuit. - Use
HashMap::entryorBTreeMap::entryfor insert-or-update logic. - Avoid unnecessary intermediate
Vecs. Chain iterators or extend an existing collection when possible. - 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_mapfor map-then-discard-None; useflat_mapwhen each item expands to zero or more items. - Use
map_whileorscanfor stateful transformations when they make stopping behavior explicit. - Add type annotations at
collectboundaries, not throughout the pipeline. - Prefer
clonedorcopiedovermap(|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
Vecfor contiguous ordered data,VecDequefor queue-like push/pop at both ends,BinaryHeapfor priority queues,HashMapfor unordered lookup, andBTreeMapfor sorted lookup or range queries. - Use
retain,drain,splice, andsplit_offinstead of mutating a collection while separately iterating over borrowed elements. - Use
Entry::or_insert_withwhen default construction is expensive. - Preserve ordering deliberately. Do not swap
BTreeMapforHashMapwhen 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_keyfollowed byinsertwhereentrywould 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.
04 同仓库更多 Skills
android-emulator-qa
Use when validating Android feature flows in an emulator with adb-driven launch, input, UI-tree inspection, screenshots, and logcat capture.
supabase-postgres-best-practices
Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.
sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
render-workflows
Sets up, develops, tests, and deploys Render Workflows. Covers first-time scaffolding (via CLI or manual), SDK installation (Python or TypeScript), task patterns (retries, subtasks, fan-out), local development, Dashboard deployment, and troubleshooting. Use when a user wants to set up Render Workflows for the first time, scaffold a workflow service, add or modify workflow tasks, test workflows locally, or deploy workflows to Render.
render-web-services
Configures Render web services—port binding, TLS, health checks, custom domains, auto-deploy, PR previews, persistent disks, and deploy lifecycle. Use when the user needs to set up a web service, fix health check failures, add a custom domain, configure zero-downtime deploys, or troubleshoot port binding issues.
render-static-sites
Deploys and configures static sites on Render's global CDN—build commands, publish paths, SPA routing, redirects, custom headers, and PR previews. Use when the user needs to deploy a static site, set up a React/Vue/Hugo/Gatsby frontend, configure SPA fallback routing, add redirect rules, customize response headers, or choose between a static site and a web service for their frontend. Trigger terms: static site, CDN, SPA, single-page app, React deploy, Vue deploy, Hugo, Gatsby, Docusaurus, Jekyll, staticPublishPath.