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
相关推荐
葫芦和十三9 分钟前
图解 MongoDB 25|分片架构三件套:mongos、config server 和 shard
后端·mongodb·agent
葫芦和十三6 小时前
图解 MongoDB 26|片键设计:决定集群命运的一个决定
后端·mongodb·agent
Avan_菜菜8 小时前
使用 Docker + rclone 自建 WebDAV
后端·agent·claude
阳光是sunny9 小时前
别再被 worktree 绕晕了!AI 编程时代你必须掌握的 Git 隔离神器
前端·人工智能·后端
万少10 小时前
万少的博客 - 技术分享与解决方案
前端·javascript·后端
咖啡八杯11 小时前
GoF设计模式——备忘录模式
java·后端·spring·设计模式
苍何11 小时前
腾讯再放大招,企微 Agent 大圆开启内测
后端
ethantan11 小时前
一篇讲解AI Agent 组成:像人一样思考的智能体
人工智能·后端·程序员
Cosolar13 小时前
vLLM 生产级部署完全指南
人工智能·后端·架构
IT_陈寒13 小时前
垃圾回收器选错了,我的Java服务内存炸了
前端·人工智能·后端