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 分钟前
2027年火的很可能是AI工作台
后端
吃我一窝jio1 小时前
Python与Go线程模型深度对比
java·开发语言·python
eggwyw2 小时前
C++ union 的一种妙用法
开发语言·c++
starzy19904 小时前
深入理解Scala隐式函数:自动类型转换
开发语言·后端·scala
IT_陈寒4 小时前
Redis那个过期删除策略,差点让我线上崩了
前端·人工智能·后端
ServBay5 小时前
Cursor披露恶意扩展,怎么守住本地 API Key
后端·ai编程·cursor
AndreaYYmm5 小时前
多台设备共享一个 NFS,怎么保证压力测试不同时跑?一把互斥锁的设计与最简验证
后端
心之语歌5 小时前
uni-app uts原生插件开发:uts 与 Kotlin 交互踩坑实录(附解决方案)
前端·后端
AndreaYYmm6 小时前
手动敲能跑,cron 一跑就 command not found?聊聊 PATH 到底从哪来
后端