Rust Pin

Rust Pin

(Jin Qing's Column, Sep., 2024)

From: https://doc.rust-lang.org/std/pin/index.html

Rust can pin data location in memory, that means its address can not be changed.

Pinned data guarantees the memory location is always valid.

Safe code can not move pinned data to another location.

Safe code users do not need to care about Pin.

  • What's moving
    • copy + ownership
    • all values are movable
      • assignment or function parameter
      • mem::replace
  • What's pinning
    • until drop
  • Address sensitivity
    • some interface is relay on pinned state
    • self-referenced type: Future
    • leverage the type system
      • Pin
    • how Pin works
      • restrict access to Ptr
    • PhantomPinned
  • Example types
    • self-referential struct
    • intrusive list
  • Drop
  • Projection and Structural Pinning
相关推荐
apcipot_rain24 分钟前
C++转Java日记(03)
java·开发语言·c++
布莱克60531 分钟前
C++ 中 map 的 insert 与 emplace:key 已存在时会覆盖吗?
开发语言·数据结构·c++·算法·map
xys_6781 小时前
深挖C++:类和对象(中)
开发语言·c++
灿飞屋1 小时前
Rust 编程其实很简单
开发语言·rust
陈随易2 小时前
纯 Go 写的 JS 引擎,跑分超过了 C 语言的 QuickJS
前端·后端·程序员
MOONICK3 小时前
QT元数据
开发语言·qt
卷无止境3 小时前
RAGFlow 项目全景报告:从文档解析引擎到 Agent 原生数据库
后端·python
D e re k ZH3 小时前
C++ 系统学习手记:从语法细节到工程实践
开发语言·数据结构·c++·算法
小Z先生4 小时前
我用 Go + 系统 WebView 写了个纯本地 Postman:不装 Electron、不连云端
后端·github
IT_陈寒4 小时前
Redis连接池泄漏那次,我差点把生产环境搞崩了
前端·人工智能·后端