知识卡片
赋值更新目标并丢弃旧值
对持有 String 的可变位置执行赋值后,目标取得新 String,原值会被销毁。用 total += price 这类复合赋值可表达累加;要更新两个绑定应分别写两次赋值。赋值结果为单位值 ()。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Expressions 把赋值理解为更新一个可写位置 · 查看原书依据
Ownership of the value is transferred from the source to the destination. The destination’s prior value, if any, is dropped.
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第05章《Expressions》|把赋值理解为更新一个可写位置,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch05.xhtml#assignment`
- 结论依据:原文把赋值的语法限制与第 3 章的非 Copy 移动和旧值销毁接起来,并举出复合赋值。
- 原始内容:Ownership of the value is transferred from the source to the destination. The destination’s prior value, if any, is dropped.