知识卡片

普通读书笔记卡 · 758.a.1.d

智能指针把部分错误移到运行时

理解等级:高级

用Rc>可表达互联与共享修改,但动态借用冲突可能在运行时返回错误或panic。它不是无代价绕过借用规则。先检查能否用清楚的拥有树或缩小借用范围解决,再按需要引入共享、同步和动态检查;unsafe应留给确有必要且可证明的底层实现。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 3. Concepts Smart pointers · 查看原书依据

      runtime panic! rather than a compile-time error. For example, one pattern that breaks the one-way flow of ownership in tree-like data structures is when there’s an “owner” pointer back from an item to the thing that owns it, as shown in Figure 3-3. These owner links are useful for moving around the data structure; for example, adding a new sibling to a Leaf

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Smart pointers》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u095-ch03-022)。 - 结论依据:原文在“runtime panic”附近的定义、例子或代码支撑本卡核心说明:用Rc<RefCell<T>>可表达互联与共享修改,但动态借用冲突可能在运行时返回错误或panic。边界按已读前提解释;示例未执行。 - 原始内容:runtime panic! rather than a compile-time error. For example, one pattern that breaks the one-way flow of ownership in tree-like data structures is when there’s an “owner” pointer back from an item to the thing that owns it, as shown in Figure 3-3. These owner links are useful for moving around the data structure; for example, adding a new sibling to a Leaf