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
相关推荐
AZaLEan__12 小时前
多源 BFS
java·开发语言·算法
笨蛋不要掉眼泪13 小时前
Java并发编程 :深入剖析LinkedBlockingQueue
java·开发语言·网络·并发
不会C语言的男孩13 小时前
C++ Primer Plus 第10章:对象和类
开发语言·c++
不会C语言的男孩13 小时前
C++ Primer Plus 第11章:使用类
开发语言·c++
Digital_Sunrise13 小时前
首发!检测你是否被中转站注入提示词攻击!
后端
fliter13 小时前
Rust 中的小字符串:smol_str 与 smartstring 的对决
后端
yujunl13 小时前
NetCore常用的中间件说明
开发语言
一个做软件开发的牛马13 小时前
Java 常用类:String不可变、新时间API与包装类陷阱
java·后端
刀法如飞14 小时前
AI时代:一文搞懂DDD领域驱动设计
后端·架构·ai编程
weixin_4684668514 小时前
Prometheus监控服务部署与实战指南
服务器·后端·python·docker·自动化·prometheus