Module s1_ownership

Source
Expand description

第二章:Rust核心概念 2.1 安全管理之内存安全

所有权相关代码

String 结构:

---  
                 buffer
                /   capacity
               /   /  length
              /   /   /
            +–––+–––+–––+
stack frame │ • │ 8 │ 6 │ <- my_name: String
            +–│–+–––+–––+
              │
            [–│–––––––– capacity –––––––––––]
              │
            +–V–+–––+–––+–––+–––+–––+–––+–––+
heap        │ P │ a │ s │ c │ a │ l │   │   │
            +–––+–––+–––+–––+–––+–––+–––+–––+
            [––––––– length ––––––––]
  
&'static str 结构:
            [–––––––––––]
            +–––+–––+
stack frame │ • │ 6 │
            +–│–+–––+
              │                 
              +––+                
                 │
preallocated   +–V–+–––+–––+–––+–––+–––+
read-only      │ P │ a │ s │ c │ a │ l │
memory         +–––+–––+–––+–––+–––+–––+

Functions§

custom_types
Rust 语义:Move 语义 与 Copy 语义
primitive_types
Rust 语义:Move 语义 与 Copy 语义
understand_clone
语义层面来理解 Clone :显式的clone方法调用同一种语义下的两种实现
understand_copy
Rust 语义:Move 语义 与 Copy 语义
understand_copy_clone
Rust 语义:Move 语义 与 Copy 语义
understand_drop
示例1: Move 的本质:drop 标记
understand_move
示例1: Box 实现 DereMove