120

Rust 所有权 - Chiyiw's Blog

 6 years ago
source link: https://chiyiw.com/blog/2017/11/05/rust-%E6%89%80%E6%9C%89%E6%9D%83/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
在 Rust 中每个值都只能被一个所有者拥有,当这个值被赋给其他所有者,原所有者无法再使用。正是这种机制保证了 Rust 语言的内存安全,从而无需自动垃圾回收,也无需手动释放。所有权是 Rust 最重要的特性之一。下面来看一个简单的例子。 [crayon-59ffd74d4994d316809002/] 上面展示了所有权转移的基本案例, 由于a获得了字符串的所有权,s无法再使用。这可能和现存的编程语言有很大的区别,事实上在 Rust

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK