rust-knowledge-patch

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rust 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)主要变化

ChangeMigration
unsafe extern "C" {}
Add
unsafe
to extern blocks
#[unsafe(no_mangle)]
Wrap unsafe attrs in
unsafe()
unsafe {}
in unsafe fns
Explicit unsafe blocks required
static mut
denied
Use atomics/sync primitives
gen
reserved
Rename identifiers
set_var
/
remove_var
unsafe
Wrap in
unsafe {}
Let chains (Edition 2024 only):
rust
if let Some(x) = opt && x > 0 && let Some(y) = other { ... }
See
references/edition-2024.md
for full migration guide.
变更内容迁移说明
unsafe extern "C" {}
为extern块添加
unsafe
关键字
#[unsafe(no_mangle)]
将unsafe属性包裹在
unsafe()
不安全函数中的
unsafe {}
需要显式的unsafe代码块
禁用
static mut
使用原子类型或同步原语替代
gen
成为保留关键字
重命名相关标识符
set_var
/
remove_var
标记为unsafe
将其包裹在
unsafe {}
代码块中
let链(仅2024版本支持):
rust
if let Some(x) = opt && x > 0 && let Some(y) = other { ... }
完整迁移指南请查看
references/edition-2024.md

Async

异步编程

  • Async closures:
    async || {}
    with
    AsyncFn
    ,
    AsyncFnMut
    ,
    AsyncFnOnce
    traits
  • OnceLock::wait
    : Block until initialization completes
  • RwLockWriteGuard::downgrade
    : Write → read lock without releasing
See
references/async-and-concurrency.md
.
  • Async闭包:带有
    AsyncFn
    AsyncFnMut
    AsyncFnOnce
    trait的
    async || {}
  • OnceLock::wait
    :阻塞直到初始化完成
  • RwLockWriteGuard::downgrade
    :无需释放锁即可将写锁降级为读锁
详情请查看
references/async-and-concurrency.md

Collections

集合类型

MethodTypes
extract_if
Vec, LinkedList, HashMap, HashSet, BTreeMap, BTreeSet
pop_if
Vec
pop_front_if
/
pop_back_if
VecDeque
get_disjoint_mut
slices, HashMap
Cell::update
Cell
Tuple collection:
(Vec<_>, Vec<_>) = iter.map(\|x\| (a, b)).collect()
See
references/collections.md
.
方法适用类型
extract_if
Vec、LinkedList、HashMap、HashSet、BTreeMap、BTreeSet
pop_if
Vec
pop_front_if
/
pop_back_if
VecDeque
get_disjoint_mut
切片、HashMap
Cell::update
Cell
元组集合转换
(Vec<_>, Vec<_>) = iter.map(|x| (a, b)).collect()
详情请查看
references/collections.md

Integers

整数类型

MethodDescription
midpoint
Exact midpoint without overflow
is_multiple_of
Divisibility check
unbounded_shl/shr
Return 0 on overflow
cast_signed/unsigned
Bit reinterpretation
*_sub_signed
Subtract signed from unsigned
strict_*
Panic on overflow (release too)
carrying_*/borrowing_*
Extended precision arithmetic
unchecked_*
UB on overflow (perf-critical)
See
references/integers-and-arithmetic.md
.
方法描述
midpoint
计算精确中点且不会溢出
is_multiple_of
整除性检查
unbounded_shl/shr
溢出时返回0
cast_signed/unsigned
位模式重解释
*_sub_signed
无符号数减去有符号数
strict_*
溢出时触发panic(release模式下同样生效)
carrying_*/borrowing_*
扩展精度算术运算
unchecked_*
溢出时产生未定义行为(针对性能关键场景)
详情请查看
references/integers-and-arithmetic.md

Slices & 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_left
    ,
    rotate_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_left
    rotate_right
详情请查看
references/slices-and-arrays.md

Strings & Paths

字符串与路径

  • Path::file_prefix
    : Filename without ANY extensions
  • PathBuf::add_extension
    : Add without replacing
  • OsStr::display
    : Lossy UTF-8 display
  • String::into_raw_parts
    : Decompose to
    (ptr, len, cap)
See
references/strings-and-paths.md
.
  • Path::file_prefix
    :获取不含任何扩展名的文件名
  • PathBuf::add_extension
    :添加扩展名而不替换原有扩展名
  • OsStr::display
    :有损UTF-8格式显示
  • String::into_raw_parts
    :将字符串分解为
    (ptr, len, cap)
详情请查看
references/strings-and-paths.md

Pointers & Memory

指针与内存

  • Trait upcasting:
    &dyn Derived
    &dyn Base
    automatic
  • NonNull
    provenance
    :
    from_ref
    ,
    without_provenance
    ,
    expose_provenance
  • MaybeUninit
    slices
    :
    write_copy_of_slice
    ,
    assume_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_provenance
    expose_provenance
  • MaybeUninit
    切片
    write_copy_of_slice
    assume_init_ref
  • 零值构造函数
    Box::new_zeroed()
    Arc::new_zeroed()
详情请查看
references/pointers-and-memory.md

Assembly & SIMD

汇编与SIMD

  • Safe
    #[target_feature]
    : No unsafe needed for decorated fns
  • asm!
    labels
    : Jump to Rust code blocks
  • asm!
    cfg
    :
    #[cfg(...)]
    on individual lines
  • Naked functions:
    #[unsafe(naked)]
    +
    naked_asm!
See
references/assembly-and-simd.md
.
  • 安全的
    #[target_feature]
    :被该属性修饰的函数无需unsafe标记
  • asm!
    标签
    :可以跳转到Rust代码块
  • asm!
    条件编译
    :在单独行上使用
    #[cfg(...)]
  • 裸函数
    #[unsafe(naked)]
    +
    naked_asm!
详情请查看
references/assembly-and-simd.md

I/O

I/O操作

  • io::pipe()
    : Cross-platform anonymous pipes
  • File::lock/unlock
    : Advisory file locking
  • i128/u128
    in FFI
    : No more warnings
See
references/io-and-process.md
.
  • io::pipe()
    :跨平台匿名管道
  • File::lock/unlock
    :建议性文件锁
  • FFI中的
    i128/u128
    :不再产生警告
详情请查看
references/io-and-process.md

Misc

其他特性

  • Result::flatten
    :
    Result<Result<T,E>,E>
    Result<T,E>
  • fmt::from_fn
    : Display from closure
  • Duration::from_mins/hours
    : Convenience constructors
  • Const
    TypeId::of
    : Compile-time type IDs
  • Const float rounding:
    floor
    ,
    ceil
    ,
    round
    in const
See
references/misc-apis.md
.
  • Result::flatten
    :将
    Result<Result<T,E>,E>
    转换为
    Result<T,E>
  • fmt::from_fn
    :通过闭包实现Display trait
  • Duration::from_mins/hours
    :便捷构造函数
  • 常量
    TypeId::of
    :编译时类型ID
  • 常量浮点数舍入:在常量上下文中支持
    floor
    ceil
    round
详情请查看
references/misc-apis.md

Cargo

Cargo工具

  • LLD default (x86_64 Linux): Faster linking
  • cargo publish --workspace
    : Multi-crate publishing
  • Auto cache cleaning: 3mo network, 1mo local
See
references/cargo-and-tooling.md
.
  • 默认使用LLD(x86_64 Linux平台):更快的链接速度
  • cargo publish --workspace
    :多 crate 批量发布
  • 自动清理缓存:网络缓存保留3个月,本地缓存保留1个月
详情请查看
references/cargo-and-tooling.md

Reference Files

参考文件

Detailed documentation in
references/
:
FileContents
edition-2024.md
Full Edition 2024 migration guide
async-and-concurrency.md
Async closures, locks, atomics
integers-and-arithmetic.md
All integer methods
collections.md
extract_if, pop_if, disjoint_mut
slices-and-arrays.md
Chunking, conversion, const ops
strings-and-paths.md
Path/String APIs
pointers-and-memory.md
Upcasting, provenance, MaybeUninit
assembly-and-simd.md
asm!, target_feature, naked fns
io-and-process.md
Pipes, FFI, file locking
misc-apis.md
Floats, Duration, formatting, cfg
cargo-and-tooling.md
LLD, workspace publish, cache
详细文档位于
references/
目录下:
文件内容
edition-2024.md
完整的2024版本迁移指南
async-and-concurrency.md
Async闭包、锁、原子类型相关内容
integers-and-arithmetic.md
所有整数相关方法
collections.md
extract_if
pop_if
disjoint_mut
等集合方法
slices-and-arrays.md
分块、转换、常量操作
strings-and-paths.md
Path/String相关API
pointers-and-memory.md
向上转型、来源追踪、MaybeUninit
assembly-and-simd.md
asm!
、target_feature、裸函数
io-and-process.md
管道、FFI、文件锁
misc-apis.md
浮点数、Duration、格式化、条件编译
cargo-and-tooling.md
LLD、工作区发布、缓存管理