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
相关推荐
万物智能1 小时前
PWM散热风扇设置—【万物智能之开源鸿蒙OpenHarmony系统实战开发系列教程】
前端·后端·算法
用户8181870627461 小时前
第29章 死信队列与延迟消息实战
java·后端
专业程序开发源1 小时前
springboot旅游推荐系统82074-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·php·课程设计·旅游
步行cgn1 小时前
Spring 注入值中含有特殊符号的处理详解
java·后端·spring
未秃头的程序猿2 小时前
全链路追踪落地一年:从翻日志到秒级定位,我们都做了什么
java·后端·面试
回家路上绕了弯2 小时前
ZCode 入门教程:从打开项目到完成一次 Java 代码修改
后端
薛定谔的算法2 小时前
M03:面向对象编程(OOP)
后端
Amos_Web2 小时前
Rspack 源码解析(八):Module、Chunk 与 Runtime ID
前端·rust·源码阅读
SamDeepThinking2 小时前
new Thread()之后发生了什么?
java·后端·面试
亦暖筑序2 小时前
AgentScope Java 实战:Agent 的状态存在哪、怎么恢复、怎么隔离?
人工智能·后端·agent