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
相关推荐
淘矿人13 分钟前
DeepSeek V4对决Claude 4.8:AI模型终极横评
java·开发语言·人工智能·python·sql·php·pygame
Curvatureflight14 分钟前
接口幂等性设计:如何避免重复提交、重复扣款和消息重复消费?
分布式·后端·架构
铁皮饭盒18 分钟前
彩色命令行,Node21自带函数1行实现 ,Bun也兼容, 附Bun.color实现渐变色的代码
前端·后端
锋行天下33 分钟前
关于websocket,真实场景踩坑经验
前端·后端
PinkSun33 分钟前
我用Spring AI做了个简历优化工具(1):Structured Output实战,让AI返回Java对象
后端
小宇子2B37 分钟前
一个 Vec 在内存里到底长什么样:从真实地址看 move 为什么不要钱
rust
skywalk816341 分钟前
你希望的「多路捕获」语法是哪种形式?具体而言,「捕获 类型为 e」指的是什么?
开发语言·编程
东风微鸣1 小时前
Argo CD 用户管理:本地用户配置与权限分离实践
git·后端
两年半的个人练习生^_^1 小时前
JMM 进阶:彻底理解 volatile 实现原理
java·开发语言
晚风吹红霞1 小时前
C++模板进阶:非类型参数、特化、分离编译与优缺点解析
开发语言·c++