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
相关推荐
破刺不会编程14 分钟前
linux线程概念和控制
linux·运维·服务器·开发语言·c++
henreash22 分钟前
NLua和C#交互
开发语言·c#·交互
Heo35 分钟前
调用通义千问大模型实现流式对话
前端·javascript·后端
萌新小白的逆袭1 小时前
《Maven 核心基础笔记(第一天)》
java·开发语言·spring
Java水解1 小时前
RabbitMQ用法的6种核心模式全面解析
后端·rabbitmq
用户4099322502121 小时前
FastAPI的查询白名单和安全沙箱机制如何确保你的API坚不可摧?
前端·后端·github
橙序员小站1 小时前
JDK17 前后写法对比:差点没认出是 Java
java·后端
肖哥弹架构1 小时前
Spring JDBCTemplate 十大性能优化秘籍:从慢如蜗牛到快如闪电!
java·后端·程序员
wenb1n1 小时前
【Oracle】套接字异常(SocketException)背后隐藏的Oracle问题:ORA-03137深度排查与解决之道
后端