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
相关推荐
咖啡八杯2 小时前
GoF设计模式——策略模式
java·后端·spring·设计模式
lizhongxuan3 小时前
AI Agent 上下文压缩利器 Headroom
后端
Csvn5 小时前
SSH 远程管理与安全加固 — 运维的守门之道
后端
IT_陈寒5 小时前
Python搞不定字符串编码?这破玩意坑我两小时!
前端·人工智能·后端
菜鸟谢7 小时前
Rust 智能指针完整详解
后端
菜鸟谢7 小时前
Rust 函数完整知识点详解
后端
爱勇宝7 小时前
淡泊名利之前,先承认我们都很焦虑
前端·后端·程序员
菜鸟谢7 小时前
Rust 闭包(Closure)完整详解
后端
ServBay7 小时前
如何利用本地技术栈构建 0 成本 AI SaaS 雏形
后端·aigc·ai编程
菜鸟谢7 小时前
Rust 集合 + 迭代器完整详解
后端