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
相关推荐
IT_陈寒33 分钟前
垃圾回收器选错了,我的Java服务内存炸了
前端·人工智能·后端
用户8356290780511 小时前
使用 Python 在 PDF 中创建与管理书签
后端·python
Nturmoils1 小时前
字段太多看不全,ksql 的展开模式和输出控制怎么用
数据库·后端
大志说编程1 小时前
Agent面试真题06: 十分钟带你快速掌握Agent记忆管理高频面试题(附详细答案)
后端·面试·ai编程
ServBay2 小时前
Claude Code 被曝植入后门,AI 时代如何安全打造本地 DevOps
后端·ai编程·claude
王二端茶倒水2 小时前
从千兆到万兆:宽带运营不能只卖套餐,要管用户生命周期从千兆到万兆:宽带运营需要管理用户生命周期
后端·网络协议·架构
网易云信3 小时前
重磅认证!网易智企智能融合通信获鸿蒙生态权威认可,斩获「Harmony Trusted SDK」认证
人工智能·后端·aigc
神奇小汤圆3 小时前
我把祖传Java项目重构后,接口响应从3s砍到了200ms,只改了这几行代码
后端
神奇小汤圆3 小时前
面试官:你们项目里的线程池是怎么用的?怎么管理的?
后端