2.4.1 `Cell`
01-
Cell — Comprehensive Rust1分钟内可阅读完
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/borrowing/interior-mutability/cell.html
2.4.1 Cell
Cell 包装一个值,并允许仅通过指向 Cell 的共享引用来获取或设置该值。但它不允许任何指向内部值的引用。由于没有引用,借用规则也就无法被破坏。
| |
Cell是一种简单的安全保障手段:它有一个接受&self的set方法。这不需要运行时检查,但要求移动值,而这本身也可能有成本。