书写技术成长之路

Rust ownership

img

为什么看起来都是一样的ownership,但结果却不一样呢?

这是因为当给变量赋值或传递参数时,数据类型有2种:

  • Copy Type 数据实现了复制,大部分的基础数据类型都实现了,或者一个数据类型实现了core::marker::Copy trait

  • Move type 大部分的非基础数据类型都属于这部分,以及struct等

参考

https://learning-rust.github.io/docs/ownership/