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
相关推荐
风落青芜1 小时前
排序算法(四):归并排序、计数排序与算法总结
c语言·开发语言·数据结构·算法·排序算法
Resean02231 小时前
讲透Java(14)泛型的本质:类型擦除与桥接方法
java·开发语言
HarmonSir4 小时前
Codex 架构解析:一条对话如何长成一个运行时系统
后端·设计模式·架构
apcipot_rain7 小时前
C++开发 面试 1Day速通
开发语言·c++·面试
时间的情敌7 小时前
Three.js GLTF 阀门 / 泵体模型加载、材质修改、状态联动(正常 / 故障 / 告警变色)
开发语言·javascript·three.js·材质
大数据技术派7 小时前
有了AI,你多久没有亲自写代码了?
后端
星恒随风7 小时前
从0实现C++ AI大模型接入SDK(七):Ollama本地模型部署、NDJSON流式响应与LLMManager模型管理
linux·开发语言·c++·人工智能·笔记
考虑考虑7 小时前
JDK27的LazyConstant
java·后端·java ee
知识搬运临时工8 小时前
加一层连接池,TPS 从 26438 掉到 12923
java·后端
琳少_8 小时前
java课堂笔记
java·开发语言·数据库·笔记