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
相关推荐
星栈25 分钟前
深度复盘:比 EventLoop 更隐蔽!Node 微任务堆积引发的线上接口雪崩事故
后端·node.js
名字还没想好☜1 小时前
Go slice 的 append 陷阱:共享底层数组导致的数据串改
开发语言·后端·golang·go·slice
bitbrowser1 小时前
Claude 账号频繁被封?转向国内可直接使用的 AI 工具
开发语言·php
诸神缄默不语1 小时前
FastAPI后端配置CORS中间件支持浏览器跨域访问
后端·fastapi
white_ant1 小时前
15-ASCII 转换工具使用指南
rust·tauri·watools
Fanta丶1 小时前
14.Activiti7 网关 排他网关ExclusiveGateway、并行网关ParallelGateway
后端
明月_清风1 小时前
robots.txt 完全指南:从入门到精通
后端·爬虫
jvmind_dev1 小时前
Java GC 实战指南(番外篇):被忽视的隐形杀手 —— Class Unloading 如何拖垮 GC
java·后端
An_s1 小时前
机器学习python之识别图中物品信息
java·linux·开发语言
明月_清风1 小时前
从零写一个"像人"的爬虫:反爬攻防实战指南
后端·爬虫