知识卡片

普通读书笔记卡 · 6074.h

unsafe转移证明责任

理解等级:中级

unsafe允许执行原始指针解引用等受限操作,责任由编译器检查转给实现者,类型有效性、别名与并发规则仍存在。应先寻找标准库或成熟安全封装,避免重复编写底层代码。已有代码使用广泛不等于永无缺陷,调用者仍要遵守其接口前提。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Item 16: Avoid writing unsafe code》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u098-ch03-026)。 - 结论依据:原文在“Adding the unsafe marker”附近的定义、例子或代码支撑本卡核心说明:unsafe允许执行原始指针解引用等受限操作,责任由编译器检查转给实现者,类型有效性、别名与并发规则仍存在。边界按已读前提解释;示例未执行。 - 原始内容:Adding the unsafe marker doesn’t mean that no rules apply—it means that you (the programmer) are now responsible for maintaining Rust’s safety guarantees, rather than the compiler.