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