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
相关推荐
实心儿儿3 分钟前
Qt — Qt 多线程
开发语言·qt
Apifox32 分钟前
Apifox 9 月更新|CLI 能力升级、GitLab 私有化部署接入与产品体验优化
前端·后端·测试
小小龙学IT35 分钟前
Go 泛型(Generics)深度解析:从类型参数到生产实践
开发语言·数据库·golang
鱼弦42 分钟前
Agent智能体 vs 传统运维:职业天花板的3倍差距?
后端
暗夜行者之光42 分钟前
LangGraph 实战:用 LangSmith 可视化追踪 AI 智能体执行轨迹
后端
hold?fish:palm44 分钟前
45 二叉树的右视图
开发语言·c++·算法
MI_farmer1 小时前
Anaconda 安装在 D 盘但虚拟环境跑到 C 盘,以及 Conda PermissionError: WinError 5 的解决方法
c语言·开发语言·conda
鱼弦1 小时前
Agent 的工具选择策略:从硬编码到动态决策
后端
Lost of 程序猿1 小时前
建造者模式实战:告别“十参数构造函数“的数据导出任务
后端·设计模式·c#·asp.net
SensorFlow1 小时前
ClickHouse 埋点事件表:先验证时间与重复,再谈漏斗看板
后端