3.5 Unsafe 函数

Unsafe 函数 — Comprehensive Rust

译文 · 基于 Comprehensive Rust

原文链接: https://google.github.io/comprehensive-rust/unsafe-rust/unsafe-functions.html

3.5 Unsafe 函数

若函数或方法有额外前置条件,必须由调用方满足才能避免未定义行为,则可将其标记为 unsafe。

Unsafe 函数可能来自两处:

  • 声明为 unsafe 的 Rust 函数。
  • extern "C" 块中的 unsafe 外部函数。
讲师备注

接下来我们分别看这两种 unsafe 函数。


3.5.1 Unsafe Rust 函数

01-Unsafe Rust 函数 — Comprehensive Rust

3.5.2 Unsafe 外部函数

02-Unsafe 外部函数 — Comprehensive Rust

3.5.3 调用 Unsafe 函数

03-调用 Unsafe 函数 — Comprehensive Rust

最后修改 August 11, 2026: 更新 (70a5af133)