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 分钟前
我学习到的Java 的 Service 分层:itf 和 impl 到底是什么?
java·后端
前端工作日常1 小时前
我学习到的JIT即时编译与机器码缓存失效
java·后端
犀利豆2 小时前
Claude Code Tools 研究系列(三)ExitPlanMode
人工智能·后端
luj_17682 小时前
星火科技助力边远地区防病攻坚
c语言·开发语言·c++·经验分享·算法
always_TT2 小时前
【Python 日志记录:logging 模块入门】
开发语言·python·php
星栈2 小时前
oh-my-pi工程级AI编码工使用体验
人工智能·后端·agent
xcLeigh2 小时前
Go入门:变量声明的五种方式详解
java·开发语言·golang
zmzb01033 小时前
C++课后习题训练记录Day175
开发语言·c++
花褪残红青杏小3 小时前
Rust图像处理第24节- 噪声模型 + 中心极限定理:椒盐噪声 + CLT 可视化
rust·webassembly·图形学
脱胎换骨-军哥3 小时前
C++ 代码规范与格式化指南
开发语言·c++·代码规范