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
相关推荐
皮皮林55115 小时前
ThreadLocal 不香了?ScopedValue才是王道?
后端
辞旧 lekkk15 小时前
【Redis初阶】常见数据类型
开发语言·数据库·c++·redis·学习·缓存·bootstrap
帅次15 小时前
Kotlin 与 Java 互操作:混合工程里的平台类型与 API 边界
java·开发语言·kotlin·suspend·nullable
X-⃢_⃢-X15 小时前
一、第一阶段:认识 Spring Boot
java·spring boot·后端
前端工作日常16 小时前
我学习到的Java程序的生命周期
java·后端
dtq042417 小时前
C语言-结构体详解
c语言·开发语言·学习
梅雅达编程笔记17 小时前
编程启蒙|Scratch 转 Python 系列第9天:字典/哈希表积木双向对照(AI大模型参数配置表实战)
开发语言·人工智能·python·numpy·pandas
持力行17 小时前
C++与Java变量声明、定义及内存分配的核心区别
java·开发语言·c++
AskHarries17 小时前
GitHub 登录配置流程
后端
jinyishu_18 小时前
C++ 继承全解:从基础到高级特性
开发语言·c++