rust-knowledge-patch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRust 1.85-1.93 Knowledge Patch
Rust 1.85-1.93 知识补丁
Claude's baseline knowledge covers Rust through 1.84. This skill provides features from 1.85 (Feb 2025) through 1.93 (Jan 2026).
Claude的基线知识覆盖到Rust 1.84版本。本Skill提供2025年2月发布的1.85版本至2026年1月发布的1.93版本之间的特性内容。
Quick Reference
快速参考
Edition 2024 (Major Changes)
2024版本(Edition 2024)主要变化
| Change | Migration |
|---|---|
| Add |
| Wrap unsafe attrs in |
| Explicit unsafe blocks required |
| Use atomics/sync primitives |
| Rename identifiers |
| Wrap in |
Let chains (Edition 2024 only):
rust
if let Some(x) = opt && x > 0 && let Some(y) = other { ... }See for full migration guide.
references/edition-2024.md| 变更内容 | 迁移说明 |
|---|---|
| 为extern块添加 |
| 将unsafe属性包裹在 |
不安全函数中的 | 需要显式的unsafe代码块 |
禁用 | 使用原子类型或同步原语替代 |
| 重命名相关标识符 |
| 将其包裹在 |
let链(仅2024版本支持):
rust
if let Some(x) = opt && x > 0 && let Some(y) = other { ... }完整迁移指南请查看。
references/edition-2024.mdAsync
异步编程
- Async closures: with
async || {},AsyncFn,AsyncFnMuttraitsAsyncFnOnce - : Block until initialization completes
OnceLock::wait - : Write → read lock without releasing
RwLockWriteGuard::downgrade
See .
references/async-and-concurrency.md- Async闭包:带有、
AsyncFn、AsyncFnMuttrait的AsyncFnOnceasync || {} - :阻塞直到初始化完成
OnceLock::wait - :无需释放锁即可将写锁降级为读锁
RwLockWriteGuard::downgrade
详情请查看。
references/async-and-concurrency.mdCollections
集合类型
| Method | Types |
|---|---|
| Vec, LinkedList, HashMap, HashSet, BTreeMap, BTreeSet |
| Vec |
| VecDeque |
| slices, HashMap |
| Cell |
Tuple collection:
(Vec<_>, Vec<_>) = iter.map(\|x\| (a, b)).collect()See .
references/collections.md| 方法 | 适用类型 |
|---|---|
| Vec、LinkedList、HashMap、HashSet、BTreeMap、BTreeSet |
| Vec |
| VecDeque |
| 切片、HashMap |
| Cell |
元组集合转换:
(Vec<_>, Vec<_>) = iter.map(|x| (a, b)).collect()详情请查看。
references/collections.mdIntegers
整数类型
| Method | Description |
|---|---|
| Exact midpoint without overflow |
| Divisibility check |
| Return 0 on overflow |
| Bit reinterpretation |
| Subtract signed from unsigned |
| Panic on overflow (release too) |
| Extended precision arithmetic |
| UB on overflow (perf-critical) |
See .
references/integers-and-arithmetic.md| 方法 | 描述 |
|---|---|
| 计算精确中点且不会溢出 |
| 整除性检查 |
| 溢出时返回0 |
| 位模式重解释 |
| 无符号数减去有符号数 |
| 溢出时触发panic(release模式下同样生效) |
| 扩展精度算术运算 |
| 溢出时产生未定义行为(针对性能关键场景) |
详情请查看。
references/integers-and-arithmetic.mdSlices & Arrays
切片与数组
- Chunking: ,
as_chunks→as_rchunks(&[[T; N]], &[T]) - Conversion: →
slice.as_array::<N>()Option<&[T; N]> - Boundaries: ,
str.ceil_char_boundary(n)floor_char_boundary(n) - Const: ,
reverse,rotate_leftrotate_right
See .
references/slices-and-arrays.md- 分块操作:、
as_chunks→as_rchunks(&[[T; N]], &[T]) - 类型转换:→
slice.as_array::<N>()Option<&[T; N]> - 边界处理:、
str.ceil_char_boundary(n)floor_char_boundary(n) - 常量操作:、
reverse、rotate_leftrotate_right
详情请查看。
references/slices-and-arrays.mdStrings & Paths
字符串与路径
- : Filename without ANY extensions
Path::file_prefix - : Add without replacing
PathBuf::add_extension - : Lossy UTF-8 display
OsStr::display - : Decompose to
String::into_raw_parts(ptr, len, cap)
See .
references/strings-and-paths.md- :获取不含任何扩展名的文件名
Path::file_prefix - :添加扩展名而不替换原有扩展名
PathBuf::add_extension - :有损UTF-8格式显示
OsStr::display - :将字符串分解为
String::into_raw_parts(ptr, len, cap)
详情请查看。
references/strings-and-paths.mdPointers & Memory
指针与内存
- Trait upcasting: →
&dyn Derivedautomatic&dyn Base - provenance:
NonNull,from_ref,without_provenanceexpose_provenance - slices:
MaybeUninit,write_copy_of_sliceassume_init_ref - Zeroed constructors: ,
Box::new_zeroed()Arc::new_zeroed()
See .
references/pointers-and-memory.md- Trait向上转型:自动转换为
&dyn Derived&dyn Base - 来源追踪:
NonNull、from_ref、without_provenanceexpose_provenance - 切片:
MaybeUninit、write_copy_of_sliceassume_init_ref - 零值构造函数:、
Box::new_zeroed()Arc::new_zeroed()
详情请查看。
references/pointers-and-memory.mdAssembly & SIMD
汇编与SIMD
- Safe : No unsafe needed for decorated fns
#[target_feature] - labels: Jump to Rust code blocks
asm! - cfg:
asm!on individual lines#[cfg(...)] - Naked functions: +
#[unsafe(naked)]naked_asm!
See .
references/assembly-and-simd.md- 安全的:被该属性修饰的函数无需unsafe标记
#[target_feature] - 标签:可以跳转到Rust代码块
asm! - 条件编译:在单独行上使用
asm!#[cfg(...)] - 裸函数:+
#[unsafe(naked)]naked_asm!
详情请查看。
references/assembly-and-simd.mdI/O
I/O操作
- : Cross-platform anonymous pipes
io::pipe() - : Advisory file locking
File::lock/unlock - in FFI: No more warnings
i128/u128
See .
references/io-and-process.md- :跨平台匿名管道
io::pipe() - :建议性文件锁
File::lock/unlock - FFI中的:不再产生警告
i128/u128
详情请查看。
references/io-and-process.mdMisc
其他特性
- :
Result::flatten→Result<Result<T,E>,E>Result<T,E> - : Display from closure
fmt::from_fn - : Convenience constructors
Duration::from_mins/hours - Const : Compile-time type IDs
TypeId::of - Const float rounding: ,
floor,ceilin constround
See .
references/misc-apis.md- :将
Result::flatten转换为Result<Result<T,E>,E>Result<T,E> - :通过闭包实现Display trait
fmt::from_fn - :便捷构造函数
Duration::from_mins/hours - 常量:编译时类型ID
TypeId::of - 常量浮点数舍入:在常量上下文中支持、
floor、ceilround
详情请查看。
references/misc-apis.mdCargo
Cargo工具
- LLD default (x86_64 Linux): Faster linking
- : Multi-crate publishing
cargo publish --workspace - Auto cache cleaning: 3mo network, 1mo local
See .
references/cargo-and-tooling.md- 默认使用LLD(x86_64 Linux平台):更快的链接速度
- :多 crate 批量发布
cargo publish --workspace - 自动清理缓存:网络缓存保留3个月,本地缓存保留1个月
详情请查看。
references/cargo-and-tooling.mdReference Files
参考文件
Detailed documentation in :
references/| File | Contents |
|---|---|
| Full Edition 2024 migration guide |
| Async closures, locks, atomics |
| All integer methods |
| extract_if, pop_if, disjoint_mut |
| Chunking, conversion, const ops |
| Path/String APIs |
| Upcasting, provenance, MaybeUninit |
| asm!, target_feature, naked fns |
| Pipes, FFI, file locking |
| Floats, Duration, formatting, cfg |
| LLD, workspace publish, cache |
详细文档位于目录下:
references/| 文件 | 内容 |
|---|---|
| 完整的2024版本迁移指南 |
| Async闭包、锁、原子类型相关内容 |
| 所有整数相关方法 |
| |
| 分块、转换、常量操作 |
| Path/String相关API |
| 向上转型、来源追踪、MaybeUninit |
| |
| 管道、FFI、文件锁 |
| 浮点数、Duration、格式化、条件编译 |
| LLD、工作区发布、缓存管理 |