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
相关推荐
Slice_cy13 小时前
Mint 自研框架设计与实现:从重复开发走向配置驱动(五)
前端·后端·架构
景同学13 小时前
把 AI 用到线上运维:可行、有效,前提是喂足信息——一次 Full GC 排障实录
java·人工智能·后端
库克克13 小时前
【C++】set 与multiset
开发语言·c++
Wang's Blog13 小时前
Go-Zero项目开发34: 微服务超时控制与重试机制实践
开发语言·微服务·golang·go-zero
神奇小汤圆13 小时前
MyBatis、MyBatis-Plus、通用 Mapper:一张图说清三者的血缘关系
后端
SamDeepThinking14 小时前
微信支付对接实战:从下单到回调的完整落地过程
后端·程序员·架构
神奇小汤圆14 小时前
架构师必备:分布式锁方案选型
后端
shengjk114 小时前
付费上班的时代,真的来了
后端
玉鸯14 小时前
旧概念还是新范式?Agent 框架集体"图化"背后的矛盾与必然
后端·llm·agent