3.2 unsafe 关键字的用途
02-unsafe 关键字的用途 — Comprehensive Rust
1分钟内可阅读完
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/unsafe-deep-dive/introduction/purpose.html
3.2 unsafe 关键字的用途
- Rust 保证安全性
- 但编译器能做的事有限
unsafe关键字让程序员承担维护 Rust 规则的责任
「Rust 的一个基本目标是保证内存安全。」
「但存在局限。有些安全考量无法用编程语言表达。即便可以表达,Rust 编译器能控制的范围也有限。」
「
unsafe关键字将维护 Rust 规则的责任从编译器转移到程序员。」「当你看到
unsafe关键字时,就意味着责任从编译器转移到了程序员。」