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
相关推荐
涡能增压发动积7 小时前
同样的代码循环 10次正常 循环 100次就抛异常?自定义 Comparator 的 bug 让我丢尽颜面
后端
Wenweno0o7 小时前
0基础Go语言Eino框架智能体实战-chatModel
开发语言·后端·golang
swg3213217 小时前
Spring Boot 3.X Oauth2 认证服务与资源服务
java·spring boot·后端
tyung7 小时前
一个 main.go 搞定协作白板:你画一笔,全世界都看见
后端·go
gelald7 小时前
SpringBoot - 自动配置原理
java·spring boot·后端
chenjingming6667 小时前
jmeter线程组设置以及串行和并行设置
java·开发语言·jmeter
cch89187 小时前
Python主流框架全解析
开发语言·python
不爱吃炸鸡柳7 小时前
C++ STL list 超详细解析:从接口使用到模拟实现
开发语言·c++·list
十五年专注C++开发7 小时前
RTTR: 一款MIT 协议开源的 C++ 运行时反射库
开发语言·c++·反射
Momentary_SixthSense8 小时前
设计模式之工厂模式
java·开发语言·设计模式