rust-pro
1
总安装量
1
周安装量
#51901
全站排名
安装命令
npx skills add https://github.com/dokhacgiakhoa/antigravity-ide --skill rust-pro
Agent 安装分布
amp
1
opencode
1
kimi-cli
1
codex
1
github-copilot
1
antigravity
1
Skill 文档
Rust Professional Development
Goal: Write idiomatic, high-performance, and memory-safe Rust code following standard community practices (The Rust Way).
1. Core Principles
- Ownership & Borrowing: strictly enforce ownership rules. Avoid
.clone()unless necessary. UseArc<Mutex<T>>orRwLock<T>for shared state only when message passing (mpsc) is not viable. - Error Handling: Use
Result<T, E>withthiserrorfor libraries andanyhowfor applications. Never use.unwrap()in production code; use.expect()with a context message or?operator. - Async Runtime: Default to
tokiofor general purpose apps. Usejoin_allfor parallel execution of futures. - Type System: Leverage traits and generics for zero-cost abstractions. Use
New Typepattern to enforce validation at compile time.
2. Toolchain & Ecosystem
- Build System:
cargo - Linter:
clippy(Treat warnings as errors in CI) - Formatter:
rustfmt - Testing: Built-in
#[test]andcargo test. Usemockallfor mocking traits.
3. Recommended Project Structure
my_crate/
âââ Cargo.toml
âââ src/
â âââ main.rs # Binary entry point
â âââ lib.rs # Library entry point
â âââ bin/ # Additional binaries
â âââ models/ # Data structures
â âââ error.rs # Central error definition
â âââ utils.rs # Helper functions
âââ tests/ # Integration tests
âââ integration_test.rs
4. Common Dependencies (The Standard Stack)
- Async:
tokio,futures - Web:
axumoractix-web - Serialization:
serde,serde_json - Error Handling:
anyhow,thiserror - Tracing/Logging:
tracing,tracing-subscriber - config:
configcrate for environment management
5. Security & Performance
- Memory: Use
Stringonly when ownership is needed; prefer&strfor function arguments. - Unsafe: Avoid
unsafeblocks unless absolutely necessary and documented with// SAFETY:comment explaining why it holds. - Vectors: Pre-allocate vectors with
Vec::with_capacity(n)if size is known.
6. Implementation Workflow
- Define Types: Start with
structandenumdefinitions. - Define Traits: Outline behavior using traits.
- Implement Logic: Implement traits for types.
- Wire up: Connect components in
main.rsorlib.rs. - Test: Write unit tests alongside code and integration tests in
tests/.
Anti-Patterns to Avoid:
- Excessive use of
Box<dyn Trait>(prefer generics with static dispatch). - Ignoring
Result(always handle or propagate). - Global mutable state (use dependency injection or actor pattern).