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
相关推荐
Solis3 分钟前
Raft:分布式系统的定海神针
后端·架构
程序员老申3 分钟前
第三篇 5 天 12 个 commit:踩坑实录与代码演进
后端·程序员
程序员鱼皮4 分钟前
提示词工程已死,Loop Engineering 称王!保姆级教程 + 项目实战
前端·后端·ai编程
(Charon)12 分钟前
【C++ 面试高频:内存管理、RAII 和智能指针详解】
java·开发语言·word
Mininglamp_271823 分钟前
Vibe Coding 之后是 Vibe Operating?
后端·开源·多智能体·ai agent·mano-p
星哥的编程之路33 分钟前
别再调 API 就说自己会 RAG 了,看看真正的企业级 AI 智能体长什么样
后端·面试
长大198835 分钟前
C++26 静态反射完整实战:告别宏代码生成,一键实现序列化
后端
yb77937 分钟前
Java 21 虚拟线程最佳实践:虚拟线程如何让高并发 Java 服务更轻更快
后端
fliter40 分钟前
绕过系统 ICMP:用 rawsock、Npcap 和 WMI 找到默认网卡
后端
AHRIKNOW41 分钟前
AFaster:一个开箱即用的 Rust 高性能后端框架模板
后端