知识卡片
有效复制不等于低成本复制
只有按位复制仍有效且字段都可Copy的类型,才适合声明Copy;拥有独占资源的对象通常不满足。即便大数组等值可以合法复制,隐式复制也可能造成成本,因此还应考虑大小与常见调用方式。Clone调用可能被优化,不把“方法调用必然更慢”当成语言保证。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 2. Traits Copy · 查看原书依据
type is large. The basic promise of Copy is that a bitwise copy is valid; however, this often goes hand in hand with an assumption that making the copy is fast. If that’s not the case, skipping Copy prevents accidental slow copies. You can’t implement Copy if some component of your type is un-Copyable in turn. If all of the components of your type are Copyab
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第2章《Copy》(spine6;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch02.html;u058-ch02-004)。
- 结论依据:原文在“type is large”附近的定义、例子或代码支撑本卡核心说明:只有按位复制仍有效且字段都可Copy的类型,才适合声明Copy;拥有独占资源的对象通常不满足。边界按已读前提解释;示例未执行。
- 原始内容:type is large. The basic promise of Copy is that a bitwise copy is valid; however, this often goes hand in hand with an assumption that making the copy is fast. If that’s not the case, skipping Copy prevents accidental slow copies. You can’t implement Copy if some component of your type is un-Copyable in turn. If all of the components of your type are Copyab