Loading...
Loading...
Compare original and translation side by side
| Topic | Reference | Load When |
|---|---|---|
| Coding Style | | Naming, imports, iterators, comments, string handling, macros |
| Error Handling | | Result, Option, ?, thiserror, anyhow, custom errors, async errors |
| Ownership & Pointers | | Lifetimes, borrowing, smart pointers, Pin, Cow, interior mutability |
| Traits & Generics | | Trait design, dispatch, GATs, sealed traits, type state pattern |
| Async & Concurrency | | Tokio, channels, streams, shutdown, runtime config, async traits |
| Sync Concurrency | | Atomics, Mutex, RwLock, lock ordering, Send/Sync, memory ordering |
| Testing | | Unit/integration/doc tests, snapshot, proptest, mockall, benchmarks, fuzz |
| Performance | | Profiling, flamegraph, cloning, stack vs heap, iterators, allocation |
| Clippy & Linting | | Clippy config, key lints, workspace setup, #[expect] vs #[allow] |
| Documentation | | Doc comments, rustdoc, doc lints, coverage checklist |
| 主题 | 参考文档 | 触发加载场景 |
|---|---|---|
| 编码风格 | | 命名、导入、迭代器、注释、字符串处理、宏 |
| 错误处理 | | Result、Option、?、thiserror、anyhow、自定义错误、异步错误 |
| 所有权与指针 | | 生命周期、借用、智能指针、Pin、Cow、内部可变性 |
| Trait与泛型 | | Trait设计、分发、GAT、密封trait、类型状态模式 |
| 异步与并发 | | Tokio、通道、流、优雅关闭、运行时配置、异步trait |
| 同步并发 | | 原子量、Mutex、RwLock、锁顺序、Send/Sync、内存序 |
| 测试 | | 单元/集成/文档测试、快照测试、proptest、mockall、基准测试、模糊测试 |
| 性能 | | 性能分析、火焰图、克隆、栈vs堆、迭代器、内存分配 |
| Clippy与Lint检查 | | Clippy配置、核心lint规则、工作区设置、#[expect] vs #[allow] |
| 文档 | | 文档注释、rustdoc、文档lint、覆盖率检查清单 |
&T.clone()&strString&[T]Vec<T>get_fn name()fn get_name()as_to_into_iter()iter_mut()into_iter()stdsuper::crate::format!+s.bytes()s.chars()&T.clone()&strString&[T]Vec<T>get_fn name()fn get_name()as_to_into_iter()iter_mut()into_iter()stdsuper::crate::format!+s.bytes()s.chars()Result<T, E>panic!unwrap()expect()?if letlet...elsethiserroranyhow?match_elseok_or_elseunwrap_or_elseinspect_errmap_errassert!Result<T, E>panic!unwrap()expect()?if letlet...elsethiserroranyhow?match_elseok_or_elseunwrap_or_elseinspect_errmap_errassert!CopyCopyCow<'_, T>'src'ctx'conn'atry_borrow()RefCell.borrow_mut()let x = x.parse()?| Pointer | When to Use |
|---|---|
| Single ownership, heap allocation, recursive types |
| Shared ownership, single-threaded |
| Shared ownership, multi-threaded |
| Interior mutability, single-threaded |
| Interior mutability, multi-threaded |
CopyCopyCow<'_, T>'src'ctx'conn'aRefCelltry_borrow().borrow_mut()let x = x.parse()?| 指针类型 | 适用场景 |
|---|---|
| 单一所有权、堆分配、递归类型 |
| 共享所有权、单线程场景 |
| 共享所有权、多线程场景 |
| 内部可变性、单线程场景 |
| 内部可变性、多线程场景 |
dyn TraitSelf: Sized&self&mut selfselfstruct Connection<S> { _state: PhantomData<S> }
struct Disconnected;
struct Connected;
impl Connection<Connected> { fn send(&self, data: &[u8]) { /* ... */ } }dyn TraitSelf: Sized&self&mut selfselfstruct Connection<S> { _state: PhantomData<S> }
struct Disconnected;
struct Connected;
impl Connection<Connected> { fn send(&self, data: &[u8]) { /* ... */ } }.awaitstd::thread::sleeptokio::time::sleepSendJoinSetCancellationTokentokio_utiltracing#[instrument]| Channel | Use Case |
|---|---|
| Multi-producer, single-consumer message passing |
| Multi-producer, multi-consumer event fan-out |
| Single value, single use (request-response) |
| Latest-value-only, change notification |
crossbeam::channelstd::sync::mpsctokio::sync::{mpsc, broadcast, oneshot, watch}AtomicBoolAtomicUsizeMutexRelaxedAcquireReleaseSeqCst.awaitstd::thread::sleeptokio::time::sleepSendJoinSettokio_utilCancellationTokentracing#[instrument]| 通道类型 | 适用场景 |
|---|---|
| 多生产者单消费者消息传递 |
| 多生产者多消费者事件广播 |
| 单次单值传递(请求-响应场景) |
| 仅传递最新值、变更通知 |
crossbeam::channelstd::sync::mpsctokio::sync::{mpsc, broadcast, oneshot, watch}AtomicBoolAtomicUsizeMutexRelaxedAcquireReleaseSeqCstprocess_should_return_error_when_input_empty()mod///cargo test --doccargo insta testcargo insta reviewrstest#[case::name]proptestmockall#[automock]criterioniter_batchedBenchmarkIdcargo-fuzzlibfuzzer_syscargo-tarpaulincargo-llvm-covsqlx::test#[should_panic]#[ignore]process_should_return_error_when_input_empty()mod///cargo test --doccargo insta testcargo insta reviewrstest#[case::name]proptestmockall#[automock]criterioniter_batchedBenchmarkIdcargo-fuzzlibfuzzer_syscargo-tarpaulincargo-llvm-covsqlx::test#[should_panic]#[ignore]--releasecargo clippy -- -D clippy::perfcargo flamegraphsamplyVec::with_capacity()String::with_capacity()for.collect()smallvecCow<'_, T>s.bytes()s.chars()--releasecargo clippy -- -D clippy::perfcargo flamegraphsamplyVec::with_capacity()String::with_capacity()for.collect()smallvecCow<'_, T>s.bytes()s.chars()cargo clippy --all-targets --all-features --locked -- -D warnings| Lint | Catches |
|---|---|
| Unnecessary |
| Unnecessary |
| Oversized variants (consider |
| Premature |
| |
| Functions always returning |
| |
#[expect(clippy::lint)]#[allow(...)]expect#![warn(clippy::all)]Cargo.tomlcargo clippy --all-targets --all-features --locked -- -D warnings| Lint规则 | 检测内容 |
|---|---|
| 不必要的 |
| 不必要的 |
| 过大的枚举变体(建议用 |
| 迭代前提前执行 |
| |
| 函数总是返回 |
| 对 |
#[expect(clippy::lint)]#[allow(...)]expect#![warn(clippy::all)]Cargo.toml///////!lib.rsmod.rsTODO// TODO(#42): description#![deny(missing_docs)]# Examples# Errors# Panics# Safety| Doc Lint | Purpose |
|---|---|
| Ensure all public items documented |
| Catch dead cross-references |
| Document panic conditions |
| Document error conditions |
| Document unsafe safety requirements |
///////!lib.rsmod.rsTODO// TODO(#42): 描述#![deny(missing_docs)]# 示例# 错误# Panic# 安全性| 文档Lint规则 | 用途 |
|---|---|
| 确保所有公共项都有文档 |
| 检测失效的内部文档链接 |
| 要求说明panic触发条件 |
| 要求说明错误触发条件 |
| 要求说明unsafe代码的安全约束 |
struct Email(String)if let [first, .., last] = sliceVeclet x = x.parse()?Cow<str>contains()struct Email(String)if let [first, .., last] = sliceVeclet x = x.parse()?Cow<str>contains()| Deprecated | Better | Since |
|---|---|---|
| | Rust 1.70 |
| | Rust 1.80 |
| | — |
| | — |
| | — |
| | Rust 2018 |
| Native | Rust 1.75 |
| 弃用用法 | 推荐替代 | 起始版本 |
|---|---|---|
| | Rust 1.70 |
| | Rust 1.80 |
| | — |
| | — |
| | — |
| | Rust 2018 |
| trait原生 | Rust 1.75 |
[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"] }Cargo.toml[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }rustfmt.tomlreorder_imports = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"[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"] }Cargo.toml[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }rustfmt.tomlreorder_imports = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"ResultOptionthiserroranyhowunsafeunsafecargo clippycargo fmt///tracingrstestproptestinstamockallcriterionResultOptionthiserroranyhowunsafeunsafecargo clippycargo fmt///tracingrstestproptestinstamockallcriterionunwrap()unsafe#[expect(...)].awaitstd::thread::sleeppanic!String&strspawn_blockingunwrap()unsafe#[expect(...)].awaitstd::thread::sleeppanic!&strStringspawn_blocking