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
相关推荐
京东云开发者17 分钟前
一份数据,两种协议:京东云存储打通文件与对象
后端
代码民工正电荷1 小时前
JAVA学习基础(一)
java·开发语言·学习
CRZZX3 小时前
ManagedAgent 设计与使用
后端·agent
wasabihu3 小时前
为什么别给 AI 浏览器 MCP 开全盘文件上传:原生 CDP 零拷贝与 4 道 Fail-Closed 防线
rust
星恒随风4 小时前
C++11 加餐(2)并发支持库——mutex、lock_guard、unique_lock 与死锁问题
开发语言·c++
狗头大军之江苏分军4 小时前
三个月的电商心得
前端·后端
JuiceFS5 小时前
4300万请求零崩溃:基于 JuiceFS 的 WordPress 高并发加速实践
后端
软件技术NINI5 小时前
基于SpringBoot的社区留守儿童帮扶系统
java·spring boot·后端
挖掘狂人6 小时前
为什么造手表的人,先造出了 “软件工厂”?
后端·ai编程
会编程的吕洞宾7 小时前
Spring Boot虚拟线程实战:吞吐提升3倍
java·经验分享·后端·spring