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
相关推荐
xxxiugou12310 分钟前
C++命名空间与引用全解析
开发语言·c++
Tokenfree13 分钟前
把多模态 OCR 接进业务系统:四千张运单,三个坑
后端
phil61 小时前
沙箱核心功能系列 06:编排调度与资源管理
后端
小兔子1 小时前
if (system(cmd) != 0) 判不出命令失败:它返回的是等待状态,不是退出码
后端
艾迪的技术之路1 小时前
16k 条慢查询,128 张分表,我这么解决
后端·github
dpharness1 小时前
我踩过的四个记忆坑,从预算到换机
前端·后端
加宝的起点雷达1 小时前
三个定时任务被删那天,系统一声不吭
人工智能·后端
泡海椒1 小时前
jquick-pdf 热力图(HEATMAP)实战:24 格营收矩阵嵌入评级报告的模板逐行拆解
后端
对象存储与RustFS1 小时前
Velero 接 RustFS 实操:K8s 集群备份落到自建对象存储
后端·docker·云原生
leo在掘金1 小时前
2.8万亿MoE跑昇腾:0 Day适配改了啥
后端·架构