Token导航 LogoToken导航

Agent Skill · 开发规范

rust-best-practices(Rust 最佳实践)

rust-best-practices 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

rust-best-practices 是开发规范类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为执行命令;许可证信息还不明确,第三方扫描已通过,按安装量在开发规范类的 1,265 个 Skill 里排第 506。

总安装 1,223周安装 52GitHub Stars 323下载 428核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:rust-best-practices(Rust 最佳实践)
来源仓库:https://github.com/pedronauck/skills
仓库路径:skills/rust-best-practices
安装命令:
npx skills add https://github.com/pedronauck/skills --skill rust-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/pedronauck/skills --skill rust-best-practices

这个 Skill 是做什么的

开发规范类 Skill 用来统一代码风格、目录结构和评审口径,产出多为检查清单或改写建议。

rust-best-practices 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。通过 npx skills add 命令从指定 GitHub 仓库安装并使用。

安装前需确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。建议结合来源仓库和原始 README 核验具体用法和功能边界。

来源仓库内路径:skills/rust-best-practices

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/pedronauck/skills --skill rust-best-practices;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要执行命令,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

rust-best-practices 怎么安装?

在终端执行 npx skills add https://github.com/pedronauck/skills --skill rust-best-practices。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

rust-best-practices 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

rust-best-practices 需要什么权限?

权限级别是执行命令。安装流程涉及命令执行,可能通过 npx skills add https://github.com/pedronauck/skills --skill rust-best-practices 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

rust-best-practices 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

rust-best-practices 用的人多吗?

公开数据是累计安装 1,223 次,近一周安装 52 次,下载 428 次,GitHub 323 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

rust-best-practices 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要执行命令,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发规范类任务、又不想每次都手写提示词的人。

不太适合

  • 不能接受 Skill 在你机器上执行命令的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发规范类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
vercel-react-best-practices

Vercel React 最佳实践 · Codex、Claude

8,490,72025,918操作浏览器MIT通过
web-design-guidelines

网页设计指南 · Codex、Claude

6,686,01625,885需要联网MIT有提醒
remotion-best-practices

Remotion 最佳实践 · Codex、Claude

6,505,6323,027操作浏览器MIT有提醒
supabase-postgres-best-practices

Supabase Postgres 最佳实践 · Codex、Claude

3,175,5232,030需要联网MIT通过
next-best-practices

Next.js 最佳实践 · Codex、Claude

1,848,240841操作浏览器MIT通过
rust-best-practices

Rust 最佳实践 · 本页

1,223323执行命令未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Rust Best Practices

Unified Rust guidelines covering coding style, ownership, error handling, async patterns, traits, testing, performance, linting, and documentation. Apply when writing or reviewing Rust code.

When to Apply

  • Writing new Rust code or designing APIs
  • Reviewing or refactoring existing Rust code
  • Implementing async systems with Tokio
  • Designing error hierarchies with thiserror/anyhow
  • Choosing between borrowing, cloning, or ownership transfer
  • Setting up tests, benchmarks, or snapshot testing
  • Configuring clippy lints and workspace settings
  • Optimizing Rust code for performance

Reference Guide

Load detailed guidance based on context. Read the relevant file when the topic arises:

TopicReferenceLoad When
Coding Stylereferences/coding-style.mdNaming, imports, iterators, comments, string handling, macros
Error Handlingreferences/error-handling.mdResult, Option,?, thiserror, anyhow, custom errors, async errors
Ownership & Pointersreferences/ownership-and-pointers.mdLifetimes, borrowing, smart pointers, Pin, Cow, interior mutability
Traits & Genericsreferences/traits-and-generics.mdTrait design, dispatch, GATs, sealed traits, type state pattern
Async & Concurrencyreferences/async-and-concurrency.mdTokio, channels, streams, shutdown, runtime config, async traits
Sync Concurrencyreferences/concurrency-sync.mdAtomics, Mutex, RwLock, lock ordering, Send/Sync, memory ordering
Testingreferences/testing.mdUnit/integration/doc tests, snapshot, proptest, mockall, benchmarks, fuzz
Performancereferences/performance.mdProfiling, flamegraph, cloning, stack vs heap, iterators, allocation
Clippy & Lintingreferences/clippy-and-linting.mdClippy config, key lints, workspace setup, #[expect] vs #[allow]
Documentationreferences/documentation.mdDoc comments, rustdoc, doc lints, coverage checklist

Quick Reference: Coding Style

  • Prefer &T over .clone() unless ownership transfer is required
  • Use &str over String, &[T] over Vec<T> in function parameters
  • No get_ prefix on getters: fn name() not fn get_name()
  • Conversion naming: as_ (cheap borrow), to_ (expensive/cloning), into_ (ownership transfer)
  • Iterator methods: iter() / iter_mut() / into_iter()
  • Import ordering: std -> external crates -> workspace crates -> super:: -> crate::
  • Comments explain *why* (safety, workarounds), not *what*
  • Use format! over string concatenation with +
  • Prefer s.bytes() over s.chars() for ASCII-only operations
  • Avoid macros unless necessary; prefer functions or generics

Quick Reference: Error Handling

  • Return Result<T, E> for fallible operations; reserve panic! for unrecoverable bugs
  • No unwrap() in production. Use expect() with descriptive message only when the value is logically guaranteed. Prefer ?, if let, let...else for all other cases
  • Use thiserror for library/crate errors, anyhow for binaries only
  • Prefer ? operator over match chains for error propagation
  • Use _else variants (ok_or_else, unwrap_or_else) to prevent eager allocation
  • Use inspect_err and map_err for logging and transforming errors
  • assert! at function entry for invariant checking (debug builds)

Quick Reference: Ownership & Pointers

  • Small Copy types (<=24 bytes, all fields Copy, no heap) pass by value
  • Use Cow<'_, T> when data may or may not need ownership
  • Meaningful lifetime names: 'src, 'ctx, 'conn — not just 'a
  • Use try_borrow() on RefCell to avoid panics; prefer over direct .borrow_mut()
  • Shadowing for transformations: let x = x.parse()?
PointerWhen to Use
Box<T>Single ownership, heap allocation, recursive types
Rc<T>Shared ownership, single-threaded
Arc<T>Shared ownership, multi-threaded
Cell<T> / RefCell<T>Interior mutability, single-threaded
Mutex<T> / RwLock<T>Interior mutability, multi-threaded

Quick Reference: Traits & Generics

  • Prefer generics (static dispatch) by default for zero-cost abstractions
  • Use dyn Trait only when heterogeneous collections or plugin architectures are needed
  • Box at API boundaries, not internally
  • Object safety: no generic methods, no Self: Sized, methods use &self/&mut self/self
  • Use sealed traits to prevent external implementors
  • Type state pattern encodes valid states in the type system:
struct Connection<S> { _state: PhantomData<S> }
struct Disconnected;
struct Connected;
impl Connection<Connected> { fn send(&self, data: &[u8]) { /* ... */ } }

Quick Reference: Async & Concurrency

  • Async for I/O-bound work, sync for CPU-bound work
  • Never hold locks across .await points — use scoped guards
  • Never use std::thread::sleep in async — use tokio::time::sleep
  • Never spawn unboundedly — use semaphores for limits
  • Ensure Send bounds on spawned futures
  • Use JoinSet for managing multiple concurrent tasks
  • Use CancellationToken (from tokio_util) for graceful shutdown
  • Instrument with tracing + #[instrument] for async debugging
ChannelUse Case
mpscMulti-producer, single-consumer message passing
broadcastMulti-producer, multi-consumer event fan-out
oneshotSingle value, single use (request-response)
watchLatest-value-only, change notification
  • Sync channels: crossbeam::channel over std::sync::mpsc
  • Async channels: tokio::sync::{mpsc, broadcast, oneshot, watch}
  • Atomics (AtomicBool, AtomicUsize) over Mutex for primitive types
  • Choose memory ordering carefully: Relaxed / Acquire / Release / SeqCst

Quick Reference: Testing

  • Name tests descriptively: process_should_return_error_when_input_empty()
  • One assertion per test when possible; include formatted failure messages
  • Group tests in mod blocks by unit of work
  • Use doc tests (///) for public API examples; run separately with cargo test --doc
  • Snapshot testing: cargo insta test then cargo insta review; redact unstable fields
  • rstest for parameterized tests with #[case::name] labels
  • proptest for property-based testing with custom strategies
  • mockall with #[automock] for mocking traits
  • criterion for benchmarks with iter_batched and BenchmarkId
  • cargo-fuzz with libfuzzer_sys for fuzz testing
  • cargo-tarpaulin or cargo-llvm-cov for code coverage
  • sqlx::test for database integration tests with automatic pool injection
  • Use #[should_panic] and #[ignore] attributes where appropriate

Quick Reference: Performance

  • Golden rule: don't guess, measure. Always benchmark with --release
  • Run cargo clippy -- -D clippy::perf for performance-related hints
  • Use cargo flamegraph or samply (macOS) for profiling
  • Avoid cloning in loops; clone at the last moment only
  • Pre-allocate: Vec::with_capacity(), String::with_capacity()
  • Prefer iterators over manual for loops; avoid intermediate .collect()
  • Stack for small types, heap for large/recursive; use smallvec for large const arrays
  • Use Cow<'_, T> to avoid unnecessary allocation
  • Prefer s.bytes() over s.chars() for ASCII-only string operations

Quick Reference: Clippy & Linting

Run regularly:

cargo clippy --all-targets --all-features --locked -- -D warnings
LintCatches
redundant_cloneUnnecessary .clone() calls
needless_borrowUnnecessary & borrows
large_enum_variantOversized variants (consider Box)
needless_collectPremature .collect() before iteration
map_unwrap_or.map().unwrap_or() chains
unnecessary_wrapsFunctions always returning Ok/Some
clone_on_copy.clone() on Copy types
  • Use #[expect(clippy::lint)] over #[allow(...)] — expect warns when lint no longer applies
  • Add justification comment on every suppression
  • Set #![warn(clippy::all)] as workspace minimum
  • Configure workspace lints in Cargo.toml with priority levels

Quick Reference: Documentation

  • // comments explain *why*: safety invariants, workarounds, design rationale
  • /// doc comments explain *what* and *how* for all public items
  • //! for module-level and crate-level documentation at top of lib.rs/mod.rs
  • Every TODO needs a linked issue: // TODO(#42): description
  • Enable #![deny(missing_docs)] for libraries
  • Include # Examples, # Errors, # Panics, # Safety sections in doc comments
Doc LintPurpose
missing_docsEnsure all public items documented
broken_intra_doc_linksCatch dead cross-references
missing_panics_docDocument panic conditions
missing_errors_docDocument error conditions
missing_safety_docDocument unsafe safety requirements

Quick Reference: Data Types & Patterns

  • Use newtypes for domain semantics: struct Email(String)
  • Prefer slice patterns: if let [first,.., last] = slice
  • Use arrays for fixed sizes; avoid Vec when length is known at compile time
  • Shadowing for transformation: let x = x.parse()?
  • Cow<str> when data might need modification of borrowed data
  • contains() on strings is O(n*m) — avoid nested string iteration

Deprecated to Modern Migration

DeprecatedBetterSince
lazy_static!std::sync::OnceLockRust 1.70
once_cell::Lazystd::sync::LazyLockRust 1.80
std::sync::mpsccrossbeam::channel (sync)—
std::sync::Mutexparking_lot::Mutex (recommended)—
failure / error-chainthiserror / anyhow—
try!()? operatorRust 2018
async-trait crateNative async fn in traits (1.75+, limited)Rust 1.75

Cargo.toml Essentials

Recommended dependencies:

[dependencies]
thiserror = "2"
anyhow = "1"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
tracing = "0.1"
tracing-subscriber = "0.3"

[dev-dependencies]
rstest = "0.25"
proptest = "1"
mockall = "0.13"
criterion = { version = "0.5", features = ["html_reports"] }
insta = { version = "1", features = ["yaml"] }

Workspace lints (Cargo.toml):

[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }

rustfmt.toml:

reorder_imports = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"

Constraints

MUST DO

  1. Use ownership and borrowing for memory safety
  2. Handle all errors explicitly via Result/Option — no silent failures
  3. Use thiserror for library errors, anyhow for binaries
  4. Minimize unsafe code; document all unsafe blocks with safety invariants
  5. Use the type system for compile-time guarantees
  6. Run cargo clippy and fix all warnings
  7. Use cargo fmt for consistent formatting
  8. Write tests including doc tests for public APIs
  9. Add /// documentation with examples for all public items
  10. Use tracing for observability in async code
  11. When reviewing or writing code, suggest a testing approach using the recommended tools (rstest, proptest, insta, mockall, criterion) — even if the user did not ask for tests

MUST NOT DO

  1. Use unwrap() in production code
  2. Create memory leaks or dangling pointers
  3. Use unsafe without documented safety invariants
  4. Ignore clippy warnings without #[expect(...)] and justification
  5. Hold locks across .await points
  6. Use std::thread::sleep in async context
  7. Skip error handling or use panic! for recoverable errors
  8. Use String where &str suffices; clone unnecessarily
  9. Spawn tasks unboundedly without semaphore limits
  10. Mix blocking and async code without spawn_blocking

平台分布

Codex

38.31%
按下载量换算164

Claude

29.77%
按下载量换算127

Cursor

19.99%
按下载量换算86

Gemini CLI

8.41%
按下载量换算36

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/pedronauck/skills --skill rust-best-practices 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills