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
相关推荐
考虑考虑6 小时前
JDK26中的Map.ofLazy
java·后端·java ee
云浪7 小时前
Go 并发实战:从零实现一个高并发安全的任务调度器
javascript·后端·go
苏三的开发日记7 小时前
Docker 启动顺序优化(CentOS / Ubuntu)
后端
高频因子挖掘机9 小时前
同一交易日出现重复 K 线:去重前先确认时间、来源和粒度
后端·github·api
feely020810 小时前
《我写了 31 个静态扫描插件,踩了 7 个「假绿」》
后端
橙子家11 小时前
参数校验类异常(Argument Exception)【C# Exception 详解系列一】
后端
掘金挖土11 小时前
前端手摸手跑路之 AI 应用开发(九)
前端·后端
全栈弄潮儿11 小时前
Python实战第8期:函数
后端·python·编程语言
码事漫谈12 小时前
你让 AI “尽力做”,它反而可能做不好
后端