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 分钟前
Flutter 如何自动上传 可以 IPA 把构建和上传分开处理
后端·ios
二月龙2 分钟前
defer 执行顺序与底层原理,90% 的人都理解不全
后端
长大19883 分钟前
新手常犯的 Go 语法错误,一次性帮你避坑
后端
小强19883 分钟前
深入理解 Go 协程 Goroutine:并发编程的核心精髓
后端
chengliu050813 分钟前
后端学习地图
后端
Java内核笔记34 分钟前
SpringSecurity源码解析(四) 认证器创建流程:从 AuthenticationConfiguration 到 ProviderManager
后端
鱼人36 分钟前
详解 Go 接口:和其他语言接口有什么不一样?
后端
.道阻且长.36 分钟前
C++ string 操作指南:接口解析
java·c语言·开发语言·c++
蚰蜒螟38 分钟前
Java 对象的内存密语:从字段偏移量计算到 Unsafe 访问的完整链路
java·开发语言
Alan_7542 分钟前
京东RESTful商品接口三大异步优化核心
后端·api