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/async-mpsc-queue.md

View on GitHub
# async-mpsc-queue

> Use `mpsc` channels for async message queues between tasks

## Why It Matters

`tokio::sync::mpsc` (multi-producer, single-consumer) is the workhorse channel for async Rust. It provides async send/receive, backpressure via bounded capacity, and efficient cloning of senders. It's the default choice for task-to-task communication.

## Bad

```rust
use std::sync::mpsc;  // Wrong! Blocks the async runtime

let (tx, rx) = std::sync::mpsc::channel();

tokio::spawn(async move {
    tx.send("hello").unwrap();  // Might block
});

tokio::spawn(async move {
    let msg = rx.recv().unwrap();  // BLOCKS the executor thread!
});
```

## Good

```rust
use tokio::sync::mpsc;

let (tx, mut rx) = mpsc::channel::<String>(100);

tokio::spawn(async move {
    tx.send("hello".to_string()).await.unwrap();
});

tokio::spawn(async move {
    while let Some(msg) = rx.recv().await {
        println!("Received: {}", msg);
    }
});
```

## Sender Cloning

```rust
use tokio::sync::mpsc;

let (tx, mut rx) = mpsc::channel::<Event>(100);

// Multiple producers
for i in 0..10 {
    let tx = tx.clone();  // Cheap clone
    tokio::spawn(async move {
        tx.send(Event { source: i }).await.unwrap();
    });
}

// Drop original sender so channel closes when all clones dropped
drop(tx);

// Consumer
while let Some(event) = rx.recv().await {
    process(event);
}
// Loop exits when all senders dropped
```

## Message Handler Pattern

```rust
use tokio::sync::mpsc;

enum Command {
    Get { key: String, reply: oneshot::Sender<Option<Value>> },
    Set { key: String, value: Value },
    Delete { key: String },
}

async fn run_store(mut commands: mpsc::Receiver<Command>) {
    let mut store = HashMap::new();
    
    while let Some(cmd) = commands.recv().await {
        match cmd {
            Command::Get { key, reply } => {
                let _ = reply.send(store.get(&key).cloned());
            }
            Command::Set { key, value } => {
                store.insert(key, value);
            }
            Command::Delete { key } => {
                store.remove(&key);
            }
        }
    }
}

// Usage
async fn client(tx: mpsc::Sender<Command>) -> Option<Value> {
    let (reply_tx, reply_rx) = oneshot::channel();
    
    tx.send(Command::Get { 
        key: "foo".to_string(), 
        reply: reply_tx 
    }).await.unwrap();
    
    reply_rx.await.unwrap()
}
```

## Graceful Shutdown

```rust
async fn worker(mut rx: mpsc::Receiver<Task>, shutdown: CancellationToken) {
    loop {
        tokio::select! {
            _ = shutdown.cancelled() => {
                // Drain remaining messages
                while let Ok(task) = rx.try_recv() {
                    process(task).await;
                }
                break;
            }
            Some(task) = rx.recv() => {
                process(task).await;
            }
            else => break,  // Channel closed
        }
    }
}
```

## WeakSender for Optional Producers

```rust
use tokio::sync::mpsc;

let (tx, mut rx) = mpsc::channel::<Message>(100);
let weak = tx.downgrade();  // Doesn't keep channel alive

tokio::spawn(async move {
    // Strong sender - keeps channel alive
    tx.send("from strong".into()).await.unwrap();
});

tokio::spawn(async move {
    // Weak sender - may fail if strong senders dropped
    if let Some(tx) = weak.upgrade() {
        tx.send("from weak".into()).await.unwrap();
    }
});
```

## Permit Pattern

```rust
// Reserve slot before preparing message
let permit = tx.reserve().await?;

// Now we have guaranteed capacity
let message = expensive_to_create_message();
permit.send(message);  // Never fails

// Useful when message creation is expensive
// and you don't want to create it if channel is full
```

## See Also

- [async-bounded-channel](./async-bounded-channel.md) - Why bounded channels
- [async-oneshot-response](./async-oneshot-response.md) - Request-response with oneshot
- [async-broadcast-pubsub](./async-broadcast-pubsub.md) - Multiple consumers
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