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
相关推荐
kfaino16 小时前
码农的AI翻身(五)你好,我叫 Transformer
后端·aigc
Oneslide1 天前
机械革命 单系统纯净重装Ubuntu(全盘覆盖,清空原有Windows)
后端
GetcharZp1 天前
告别OOM!用Go+libvips实现30000×50000超大图片的流式瓦片服务
后端·go
IT_陈寒1 天前
JavaScript项目实战经验分享
前端·人工智能·后端
用户47949283569151 天前
6w star,GitHub 趋势第一的 Ponytail,这个agent插件到底在火什么
前端·后端
神奇小汤圆1 天前
2026一线大厂Java八股文精选(附答案,高质量整理)
后端
Warson_L1 天前
LangGraph入门学习资料
后端
神奇小汤圆1 天前
Spring Boot → Solon 注解迁移实战指南:一张对照表说清楚
后端
kfaino1 天前
码农的AI翻身(四)你好,我叫 Attention
人工智能·后端
lwx572801 天前
探秘InnoDB:搞懂它的内存、线程、磁盘与日志刷盘策略
java·后端