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
相关推荐
lightqjx37 分钟前
【C++】unordered系列的封装
开发语言·c++·stl·unordered系列
掘金者阿豪42 分钟前
关系数据库迁移的“暗礁”:金仓数据库如何规避数据完整性与一致性风险
后端
zh_xuan1 小时前
kotlin lazy委托异常时执行流程
开发语言·kotlin
ServBay1 小时前
一个下午,一台电脑,终结你 90% 的 Symfony 重复劳动
后端·php·symfony
sino爱学习1 小时前
高性能线程池实践:Dubbo EagerThreadPool 设计与应用
java·后端
阿猿收手吧!1 小时前
【C++】string_view:高效字符串处理指南
开发语言·c++
颜酱1 小时前
从二叉树到衍生结构:5种高频树结构原理+解析
javascript·后端·算法
掘金者阿豪1 小时前
UUID的隐形成本:一个让数据库“慢下来”的陷阱
后端
用户084465256372 小时前
Docker 部署 MongoDB Atlas 到服务端
后端
玄同7652 小时前
我的 Trae Skill 实践|使用 UV 工具一键搭建 Python 项目开发环境
开发语言·人工智能·python·langchain·uv·trae·vibe coding