Skip to content

BumpyClock/agent-templates / skills_archive/rust-skills

rust-skills

Unverified

Rust guidance for ownership, APIs, concurrency, and safety. Use when writing, reviewing, or refactoring Rust code.

FileKindSize
.github/workflows/ci.ymlconfig679 B
AGENTS.mdmarkdown8 B
CHANGELOG.mdmarkdown3.3 KB
CLAUDE.mdmarkdown8 B
CONTRIBUTING.mdmarkdown2.6 KB
LICENSEother1.0 KB
README.mdmarkdown9.9 KB
RULES.mdmarkdown36.2 KB
SKILL.mdskill md1.6 KB
agents/openai.yamlconfig255 B
checks/.gitignoreother68 B
checks/Cargo.lockmanifest41.6 KB
checks/Cargo.tomlmanifest1.1 KB
checks/README.mdmarkdown2.7 KB
checks/analyze.pyscript5.7 KB
checks/baseline.txtmarkdown8.2 KB
checks/check.shscript1.3 KB
checks/gen.pyscript3.4 KB
checks/gen_index.pyscript5.6 KB
checks/rust-toolchain.tomlconfig218 B
checks/src/lib.rsscript143 B
checks/test_index.pyscript2.8 KB
checks/validate.pyscript2.0 KB
rules/anti-clone-excessive.mdmarkdown2.6 KB
rules/anti-collect-intermediate.mdmarkdown3.2 KB
rules/anti-empty-catch.mdmarkdown3.1 KB
rules/anti-expect-lazy.mdmarkdown2.6 KB
rules/anti-format-hot-path.mdmarkdown3.6 KB
rules/anti-index-over-iter.mdmarkdown2.8 KB
rules/anti-lock-across-await.mdmarkdown3.1 KB
rules/anti-over-abstraction.mdmarkdown3.1 KB
rules/anti-panic-expected.mdmarkdown3.3 KB
rules/anti-premature-optimize.mdmarkdown3.7 KB
rules/anti-string-for-str.mdmarkdown2.6 KB
rules/anti-stringly-typed.mdmarkdown4.1 KB
rules/anti-type-erasure.mdmarkdown3.6 KB
rules/anti-unwrap-abuse.mdmarkdown3.3 KB
rules/anti-vec-for-slice.mdmarkdown2.5 KB
rules/api-builder-must-use.mdmarkdown3.8 KB
rules/api-builder-pattern.mdmarkdown4.6 KB
rules/api-common-traits.mdmarkdown4.3 KB
rules/api-default-impl.mdmarkdown4.0 KB
rules/api-extension-trait.mdmarkdown3.8 KB
rules/api-from-not-into.mdmarkdown3.3 KB
rules/api-impl-asref.mdmarkdown3.5 KB
rules/api-impl-fromiterator.mdmarkdown3.4 KB
rules/api-impl-into.mdmarkdown4.0 KB
rules/api-must-use.mdmarkdown3.5 KB
rules/api-newtype-safety.mdmarkdown3.9 KB
rules/api-non-exhaustive.mdmarkdown3.9 KB
rules/api-operator-overload.mdmarkdown3.3 KB
rules/api-parse-dont-validate.mdmarkdown4.3 KB
rules/api-sealed-trait.mdmarkdown4.5 KB
rules/api-serde-optional.mdmarkdown4.2 KB
rules/api-typestate.mdmarkdown4.9 KB
rules/async-async-fn-bounds.mdmarkdown3.4 KB
rules/async-bounded-channel.mdmarkdown4.5 KB
rules/async-broadcast-pubsub.mdmarkdown4.1 KB
rules/async-cancel-safety.mdmarkdown4.3 KB
rules/async-cancellation-token.mdmarkdown4.8 KB
rules/async-clone-before-await.mdmarkdown4.0 KB
rules/async-fn-in-trait.mdmarkdown3.6 KB
rules/async-join-parallel.mdmarkdown4.0 KB
rules/async-joinset-structured.mdmarkdown4.5 KB
rules/async-mpsc-queue.mdmarkdown3.9 KB
rules/async-no-lock-await.mdmarkdown4.0 KB
rules/async-oneshot-response.mdmarkdown4.5 KB
rules/async-select-racing.mdmarkdown4.6 KB
rules/async-spawn-blocking.mdmarkdown3.6 KB
rules/async-tokio-fs.mdmarkdown4.1 KB
rules/async-tokio-runtime.mdmarkdown4.5 KB
rules/async-try-join.mdmarkdown4.3 KB
rules/async-watch-latest.mdmarkdown4.5 KB
rules/closure-disjoint-capture.mdmarkdown3.5 KB
rules/closure-fn-trait-bounds.mdmarkdown2.9 KB
rules/closure-impl-fn-return.mdmarkdown2.8 KB
rules/closure-move-capture.mdmarkdown2.9 KB
rules/closure-static-vs-dyn.mdmarkdown3.2 KB
rules/coll-binaryheap.mdmarkdown3.5 KB
rules/coll-map-choice.mdmarkdown3.6 KB
rules/coll-seq-choice.mdmarkdown2.9 KB
rules/coll-set-membership.mdmarkdown3.1 KB
rules/conc-atomic-ordering.mdmarkdown3.5 KB
rules/conc-rayon-par-iter.mdmarkdown2.4 KB
rules/conc-scoped-threads.mdmarkdown2.7 KB
rules/conc-thread-local.mdmarkdown2.6 KB
rules/const-block.mdmarkdown2.9 KB
rules/const-fn.mdmarkdown2.1 KB
rules/const-generics.mdmarkdown2.7 KB
rules/const-vs-static.mdmarkdown2.8 KB
rules/conv-asmut-mutable.mdmarkdown2.1 KB
rules/conv-fromstr-parsing.mdmarkdown2.5 KB
rules/conv-tryfrom-fallible.mdmarkdown2.3 KB
rules/doc-all-public.mdmarkdown2.7 KB
rules/doc-cargo-metadata.mdmarkdown3.2 KB
rules/doc-crate-readme.mdmarkdown2.1 KB
rules/doc-errors-section.mdmarkdown3.2 KB
rules/doc-examples-section.mdmarkdown2.9 KB
rules/doc-hidden-setup.mdmarkdown3.5 KB
rules/doc-intra-links.mdmarkdown3.3 KB
rules/doc-link-types.mdmarkdown3.8 KB
rules/doc-module-inner.mdmarkdown2.8 KB
rules/doc-panics-section.mdmarkdown3.1 KB
rules/doc-question-mark.mdmarkdown3.2 KB
rules/doc-safety-section.mdmarkdown3.8 KB
rules/err-anyhow-app.mdmarkdown4.2 KB
rules/err-context-chain.mdmarkdown3.5 KB
rules/err-custom-type.mdmarkdown4.0 KB
rules/err-doc-errors.mdmarkdown3.8 KB
rules/err-expect-bugs-only.mdmarkdown3.7 KB
rules/err-from-impl.mdmarkdown3.9 KB
rules/err-lowercase-msg.mdmarkdown3.3 KB
rules/err-no-unwrap-prod.mdmarkdown3.1 KB
rules/err-question-mark.mdmarkdown3.3 KB
rules/err-result-over-panic.mdmarkdown3.4 KB
rules/err-source-chain.mdmarkdown3.8 KB
rules/err-thiserror-lib.mdmarkdown4.1 KB
rules/lint-cargo-metadata.mdmarkdown2.8 KB
rules/lint-cfg-check.mdmarkdown2.4 KB
rules/lint-clippy-nursery-selected.mdmarkdown2.6 KB
rules/lint-deny-correctness.mdmarkdown2.2 KB
rules/lint-missing-docs.mdmarkdown2.9 KB
rules/lint-pedantic-selective.mdmarkdown3.1 KB
rules/lint-rustfmt-check.mdmarkdown2.7 KB
rules/lint-unsafe-doc.mdmarkdown3.1 KB
rules/lint-warn-complexity.mdmarkdown3.0 KB
rules/lint-warn-perf.mdmarkdown3.2 KB
rules/lint-warn-style.mdmarkdown2.9 KB
rules/lint-warn-suspicious.mdmarkdown2.9 KB
rules/lint-workspace-lints.mdmarkdown3.6 KB
rules/macro-export-crate-path.mdmarkdown2.6 KB
rules/macro-fragment-specifiers.mdmarkdown2.9 KB
rules/macro-prefer-functions.mdmarkdown2.1 KB
rules/macro-private-helpers.mdmarkdown3.0 KB
rules/macro-proc-error-spans.mdmarkdown3.7 KB
rules/macro-proc-syn-quote.mdmarkdown3.5 KB
rules/macro-proc-two-crate.mdmarkdown3.8 KB
rules/macro-rules-hygiene.mdmarkdown2.8 KB
rules/mem-arena-allocator.mdmarkdown4.4 KB
rules/mem-arrayvec.mdmarkdown3.6 KB
rules/mem-assert-type-size.mdmarkdown3.8 KB
rules/mem-avoid-format.mdmarkdown3.5 KB
rules/mem-box-large-variant.mdmarkdown3.7 KB
rules/mem-boxed-slice.mdmarkdown3.5 KB
rules/mem-clone-from.mdmarkdown3.5 KB
rules/mem-compact-string.mdmarkdown3.7 KB
rules/mem-drop-order.mdmarkdown4.5 KB
rules/mem-reuse-collections.mdmarkdown4.2 KB
rules/mem-smaller-integers.mdmarkdown3.9 KB
rules/mem-smallvec.mdmarkdown3.4 KB
rules/mem-take-replace.mdmarkdown3.5 KB
rules/mem-thinvec.mdmarkdown3.2 KB
rules/mem-with-capacity.mdmarkdown3.7 KB
rules/mem-write-over-format.mdmarkdown4.3 KB
rules/mem-zero-copy.mdmarkdown4.0 KB
rules/name-acronym-word.mdmarkdown2.8 KB
rules/name-as-free.mdmarkdown2.3 KB
rules/name-consts-screaming.mdmarkdown2.2 KB
rules/name-crate-no-rs.mdmarkdown2.0 KB
rules/name-funcs-snake.mdmarkdown1.9 KB
rules/name-into-ownership.mdmarkdown2.7 KB
rules/name-is-has-bool.mdmarkdown3.2 KB
rules/name-iter-convention.mdmarkdown3.3 KB
rules/name-iter-method.mdmarkdown3.3 KB
rules/name-iter-type-match.mdmarkdown3.6 KB
rules/name-lifetime-short.mdmarkdown2.3 KB
rules/name-no-get-prefix.mdmarkdown3.0 KB
rules/name-to-expensive.mdmarkdown2.9 KB
rules/name-type-param-single.mdmarkdown2.3 KB
rules/name-types-camel.mdmarkdown1.8 KB
rules/name-variants-camel.mdmarkdown1.8 KB
rules/num-cast-try-from.mdmarkdown3.1 KB
rules/num-float-compare.mdmarkdown3.2 KB
rules/num-nonzero.mdmarkdown3.4 KB
rules/num-overflow-explicit.mdmarkdown2.7 KB
rules/num-saturating-clamp.mdmarkdown3.1 KB
rules/obs-error-chain.mdmarkdown3.4 KB
rules/obs-instrument-spans.mdmarkdown3.2 KB
rules/obs-levels-filter.mdmarkdown3.4 KB
rules/obs-library-facade.mdmarkdown2.6 KB
rules/obs-no-sensitive-data.mdmarkdown3.5 KB
rules/obs-structured-fields.mdmarkdown2.7 KB
rules/obs-tracing-over-log.mdmarkdown2.2 KB
rules/opt-bounds-check.mdmarkdown4.1 KB
rules/opt-cache-friendly.mdmarkdown4.5 KB
rules/opt-codegen-units.mdmarkdown3.3 KB
rules/opt-cold-unlikely.mdmarkdown3.5 KB
rules/opt-inline-always-rare.mdmarkdown3.3 KB
rules/opt-inline-never-cold.mdmarkdown4.3 KB
rules/opt-inline-small.mdmarkdown3.9 KB
rules/opt-likely-hint.mdmarkdown4.2 KB
rules/opt-lto-release.mdmarkdown3.3 KB
rules/opt-pgo-profile.mdmarkdown4.1 KB
rules/opt-simd-portable.mdmarkdown4.0 KB
rules/opt-target-cpu.mdmarkdown3.8 KB
rules/own-arc-shared.mdmarkdown3.4 KB
rules/own-borrow-over-clone.mdmarkdown2.4 KB
rules/own-clone-explicit.mdmarkdown3.4 KB
rules/own-copy-small.mdmarkdown3.0 KB
rules/own-cow-conditional.mdmarkdown3.5 KB

rules/mem-arrayvec.md

View on GitHub
# mem-arrayvec

> Use `ArrayVec<T, N>` for fixed-capacity collections that never heap-allocate

## Why It Matters

`ArrayVec` from the `arrayvec` crate provides Vec-like API with a compile-time maximum capacity, storing all elements inline on the stack. Unlike `SmallVec` which can spill to heap, `ArrayVec` guarantees no heap allocation—if you exceed capacity, it returns an error or panics. This is ideal for embedded systems, real-time code, or when you have a hard upper bound.

## Bad

```rust
// Vec always heap-allocates, even for small collections
fn parse_options(input: &str) -> Vec<Option> {
    let mut options = Vec::new();  // Heap allocation
    for part in input.split(',').take(8) {  // Know we never exceed 8
        options.push(parse_option(part));
    }
    options
}

// Or SmallVec when you truly can't exceed capacity
use smallvec::SmallVec;
fn get_flags() -> SmallVec<[Flag; 4]> {
    // SmallVec CAN heap-allocate if pushed beyond 4
    // That might be unexpected in no-alloc contexts
}
```

## Good

```rust
use arrayvec::ArrayVec;

// Guaranteed no heap allocation
fn parse_options(input: &str) -> ArrayVec<Option<u32>, 8> {
    let mut options = ArrayVec::new();
    for part in input.split(',') {
        if options.try_push(parse_option(part)).is_err() {
            break;  // Capacity reached, stop
        }
    }
    options
}

// For embedded/no_std contexts
#[no_std]
fn collect_readings() -> ArrayVec<SensorReading, 16> {
    let mut readings = ArrayVec::new();
    for sensor in SENSORS.iter() {
        readings.push(sensor.read());  // Panics if > 16
    }
    readings
}
```

## ArrayVec vs SmallVec vs Vec

| Type | Stack | Heap | Use When |
|------|-------|------|----------|
| `Vec<T>` | Never | Always | Unknown size, may grow indefinitely |
| `SmallVec<[T; N]>` | Up to N | Beyond N | Usually small, occasionally large |
| `ArrayVec<T, N>` | Always | Never | Hard limit, no heap allowed |

## API Patterns

```rust
use arrayvec::ArrayVec;

let mut arr: ArrayVec<i32, 4> = ArrayVec::new();

// Push with potential panic (like Vec)
arr.push(1);
arr.push(2);

// Safe push - returns Err if full
match arr.try_push(3) {
    Ok(()) => println!("Added"),
    Err(err) => println!("Full, couldn't add {}", err.element()),
}

// Check capacity
assert!(arr.len() < arr.capacity());

// Remaining capacity
let remaining = arr.remaining_capacity();

// Is it full?
if arr.is_full() {
    arr.pop();
}

// From iterator with limit
let arr: ArrayVec<_, 10> = (0..100)
    .filter(|x| x % 2 == 0)
    .take(10)  // Important: don't exceed capacity
    .collect();
```

## ArrayString for Stack Strings

```rust
use arrayvec::ArrayString;
use std::fmt::Write; // brings the write! target trait into scope

// Stack-allocated string with max capacity
let mut s: ArrayString<64> = ArrayString::new();
s.push_str("Hello, ");
s.push_str("world!");

// No heap allocation for small strings
fn format_code(code: u32) -> ArrayString<16> {
    let mut s = ArrayString::new();
    write!(&mut s, "CODE-{:04}", code).unwrap();
    s
}
```

## When NOT to Use ArrayVec

```rust
// ❌ When size varies widely
fn parse_json_array(json: &str) -> ArrayVec<Value, ???> {
    // What capacity? JSON arrays can be any size
}

// ❌ When capacity is very large
let big: ArrayVec<u8, 1_000_000> = ArrayVec::new();  // 1MB on stack = bad

// ✅ Use SmallVec or Vec instead for these cases
```

## Cargo.toml

```toml
[dependencies]
arrayvec = "0.7"
```

## See Also

- [mem-smallvec](./mem-smallvec.md) - When heap fallback is acceptable
- [mem-with-capacity](./mem-with-capacity.md) - Pre-allocating Vec capacity
- [own-move-large](./own-move-large.md) - Large stack types considerations
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 319kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 319kUpdated Claude CodeCodexVerifiedInstall