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
相关推荐
牛奔7 小时前
Go语言中结构体转Map优雅实现
开发语言·后端·macos·golang·xcode
掘金码甲哥7 小时前
我不允许谁还分不清这三种watch机制的区别
后端
wujj_whut7 小时前
【Conda实战】从0到1:虚拟环境创建、多Python版本管理与环境切换全指南
开发语言·python·conda
蜗牛^^O^7 小时前
java中的JUC
java·开发语言
张心独酌7 小时前
Rust新手练习案例库- rust-learning-example
开发语言·后端·rust
扶苏-su8 小时前
Java--转换流-InputStreamReader 和 OutputStreamWriter
java·开发语言
码事漫谈8 小时前
一文读懂“本体论”这个时髦词
后端
IguoChan8 小时前
D2L(2) — softmax回归
后端
无限进步_8 小时前
【C语言&数据结构】二叉树遍历:从前序构建到中序输出
c语言·开发语言·数据结构·c++·算法·github·visual studio
码事漫谈8 小时前
C++线程编程模型演进:从Pthread到jthread的技术革命
后端