← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6074.e.3.e · 生成模型:未记录

可变借用要求独占

理解等级:中级

对同一位置,在有效借用重叠时可以同时持有共享引用,或持有独占可变引用。第二次冲突借用通常会被拒绝。上个引用最后一次使用后,即使语法块尚未结束,编译器也可允许新借用。这个约束有助于排除数据竞争。

相关卡片 [[借用以引用传递访问]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 理解所有权 References and Borrowing · 查看原书依据

      The restriction preventing multiple mutable references to the same data at the same time allows for mutation but in a very controlled fashion. It’s something that new Rustaceans struggle with because most languages let you mutate whenever you’d like. The benefit of having this restriction is that Rust can prevent data races at compile time.

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第04章 理解所有权(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c04.xhtml`,块 0154) - 结论依据:原文把可变访问限制连到数据竞争的并发读写条件。 - 原始内容:The restriction preventing multiple mutable references to the same data at the same time allows for mutation but in a very controlled fashion. It’s something that new Rustaceans struggle with because most languages let you mutate whenever you’d like. The benefit of having this restriction is that Rust can prevent data races at compile time.