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
相关推荐
浏览器工程师13 小时前
AI Agent 接浏览器任务,先别让它一路点到底
前端·后端
行者全栈架构师13 小时前
Maven dependency:tree 的 8 个高级用法
java·后端
Chenyiax13 小时前
从一次请求看懂 OkHttp:架构、调度与连接管理
后端
爱勇宝14 小时前
深扒 Anthropic 1680 位工程师简历:应届生几乎没机会,AI 公司最缺的不是博士
前端·后端·程序员
AskHarries14 小时前
工具失败时怎么办:重试、回滚、人工确认和风险提示
后端·程序员
苏三说技术16 小时前
Claude Code从失控到起飞,只用了这些技巧
后端
长栎17 小时前
写 for 循环写了十年,你却从没用过迭代器模式最狠的那一面
后端
LiaCode17 小时前
Redis 在生产项目的使用
前端·后端
用户5598224812217 小时前
Docker Compose Down 导致容器数据误删——ext4 日志恢复全记录
后端
LiaCode17 小时前
一天学完 redis 的爽翻版核心知识总结
前端·后端