知识卡片
包装顺序决定修改粒度
Rc>>共享整个向量,并对整个向量实施动态借用;Rc>>共享向量结构,但每个元素各有动态借用状态。两者都不自动具备跨线程同步能力,区别在于独占修改的范围。读类型嵌套顺序能直接看出共享对象与可变单元分别位于哪里。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 1. Types Smart Pointer Types · 查看原书依据
Rc<RefCell<Vec<T>>>, anyone?). The first smart pointer type is Rc<T>, which is a reference-counted pointer to an item (roughly analogous to C++’s std::shared_ptr<T>). It implements all of the pointer-related traits and so acts like a Box<T> in many ways. This is useful for data structures where the same item can be reached in different ways, but it removes o
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Smart Pointer Types》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u046-ch01-070)。
- 结论依据:原文在“Rc<RefCell<Vec<T>>>”附近的定义、例子或代码支撑本卡核心说明:Rc<RefCell<Vec<T>>>共享整个向量,并对整个向量实施动态借用;Rc<Vec<RefCell<T>>>共享向量结构,但每个元素各有动态借用状态。边界按已读前提解释;示例未执行。
- 原始内容:Rc<RefCell<Vec<T>>>, anyone?). The first smart pointer type is Rc<T>, which is a reference-counted pointer to an item (roughly analogous to C++’s std::shared_ptr<T>). It implements all of the pointer-related traits and so acts like a Box<T> in many ways. This is useful for data structures where the same item can be reached in different ways, but it removes o