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
相关推荐
新*3 分钟前
Elasticsearch 索引别名入门:创建、路由、原子切换与几个常见误解
运维·后端·elasticsearch·索引别名
挖掘狂人6 分钟前
用户连点两次「确认支付」,你的后端凭什么只扣一次钱?
java·后端·面试
卷无止境27 分钟前
AI 加速开发之后,如何应对尚未发现的代码安全威胁
后端·python
Rain的Java大神之路29 分钟前
面试官问"MySQL 大表 COUNT(*) 怎么优化",90% 的人第一步就答错了
java·后端·面试
nice_lcj52037 分钟前
MySQL 慢查询与 EXPLAIN:怎么定位、怎么优化
java·数据库·后端·mysql
饿了吃洗衣凝珠38 分钟前
SELinux
服务器·开发语言·php
蜗牛一步步往上爬42 分钟前
第四章 更多的bash shell命令
linux·开发语言·bash
回家路上绕了弯1 小时前
AI中判断的残值
后端
Java旅途1 小时前
高校实习管理系统|把岗位、指导与考核连成一条协同流程
后端