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
相关推荐
凌虚12 分钟前
基于 PostgreSQL WAL 构建 CDC 系统:原理与工程实现
数据库·后端·postgresql
东方小月21 分钟前
从零开发一个Coding Agent:monorepo项目搭建
前端·后端·node.js
FF2501_9402285825 分钟前
HarmonyOS开发实战:小分享-App项目架构全景解析
后端·华为·harmonyos·鸿蒙
AC赳赳老秦26 分钟前
企业工商公开信息采集分析:OpenClaw 批量查询企业工商信息,生成企业画像报告
大数据·开发语言·python·自动化·php·deepseek·openclaw
长大198834 分钟前
解决 PHP 常见内存溢出问题:从日志定位到代码优化实战
后端
大勇前进39 分钟前
Composer 保姆级教程:依赖冲突、版本锁、国内镜像避坑
后端
qq_2518364571 小时前
基于java Web 动漫视频网站毕业论文
java·开发语言·前端
野生风长1 小时前
C++入门基础:从命名空间到引用与指针的全面解析
开发语言·c++
未秃头的程序猿1 小时前
给公司做了个AI客服Agent,用的Spring AI 1.0,3天上线领导拍板了
java·后端·ai编程
FoldWinCard1 小时前
D6 Python 基础语法 --- 保留关键字
开发语言·python