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
相关推荐
浩浩kids2 分钟前
R•Homework
开发语言·r语言
子兮曰3 分钟前
AI写代码坑了90%程序员!这5个致命bug,上线就炸(附避坑清单)
前端·javascript·后端
Rust研习社4 分钟前
深入理解 Rust 的所有权、借用和生命周期
rust
BUG胡汉三11 分钟前
自建在线文档编辑服务:基于 Collabora CODE + Spring Boot + Vue 3 的完整实现
vue.js·spring boot·后端·在线编辑
qq_4160187215 分钟前
设计模式在C++中的实现
开发语言·c++·算法
Evand J18 分钟前
【MATLAB教程】在matlab中,gscatter和scatter两个命令的区别
开发语言·matlab·教程·绘图·命令·教学
我还不赖27 分钟前
什么是MCP?什么是Skill?它们又有什么区别和联系?
后端
像颗糖32 分钟前
Docker 与 Docker Compose 通用实战指南(从安装到区别)
后端
2301_7765087234 分钟前
C++与机器学习框架
开发语言·c++·算法
Memory_荒年35 分钟前
Spring Security + OAuth2 + JWT:三剑客合璧,打造“无懈可击”的微服务安全防线
java·后端·spring