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
相关推荐
站大爷IP20 分钟前
Python循环中修改字典键导致遍历异常深度解析实战案例
后端
掘金者阿豪3 小时前
高可用读写分离实战(二):我把数据库主库停了,结果整个集群的反应和我想象的不一样
后端
掘金者阿豪3 小时前
《高可用读写分离集群实战》系列(一)
后端
Dilee4 小时前
Spring AI 2.0.0 Prompt 最小 Demo:system、user、template 到底怎么分工
后端
未秃头的程序猿4 小时前
Java 26正式发布!这3个新特性,让代码量直接减半
java·后端·面试
小旭Coding4 小时前
卧靠!Go 传给前端的 int64 竟然变成了这个?
后端
用户298698530144 小时前
Word 文档文本查找与替换的 Java 实现方案
java·后端