8.3 Pin<Ptr> 的定义
03-Pin 的定义 — Comprehensive Rust
1分钟内可阅读完
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/unsafe-deep-dive/pinning/definition-of-pin.html
8.3 Pin 的定义
| |
Pin是对 指针类型 的最小包装;指针类型定义为实现了Deref的类型。然而,
Pin::new()只接受解引用目标实现了Unpin的类型(Deref<Target: Unpin>)。这使Pin能够依赖类型系统来强制其保证。未实现
Unpin的类型——即需要 pinning 的类型——必须通过 unsafe 的Pin::new_unchecked()创建Pin。旁注:与其他
new()/new_unchecked()方法对不同,new不做任何运行时检查。检查是零成本的编译期检查。