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
相关推荐
luj_176814 分钟前
一线一区一变破解人盯人防守密码
开发语言·网络·c++·经验分享·算法
不才不才不不才17 分钟前
Spring 源码系列(27): @Transactional 七大失效场景与源码归因
java·后端·spring
妙码生花25 分钟前
PHP 各框架下和 Go 的性能比较
前端·后端·go
名字还没想好☜33 分钟前
Python 字符编码实战:encode/decode、UnicodeDecodeError 与 open 的 encoding 坑
开发语言·后端·python·编程语言
萧瑟余晖34 分钟前
持久层选型与框架对比详解
开发语言·架构
CodeStats37 分钟前
【Java 类加载器】Java 类加载器完整体系深度拆解(上):从 JVM 启动到双亲委派模型
java·开发语言·jvm·classloader·双亲委派
大勇前进1 小时前
Java 线程创建的 4 种方式,优缺点对比,开发推荐写法
后端
明月_清风1 小时前
Foundry Web3 测试框架入门:从 0 开始写 Solidity 测试
后端·web3·solidity
万少1 小时前
等不到 Apple 的折叠 iPhone,我用 DeepV4.1Flash + workBuddy 一句话自己造了一台
前端·javascript·后端
软件黑马王子1 小时前
24.Editor 资源加载:主要作用和基本原理
开发语言·前端框架·c#