知识卡片
共享读与独占写
&T 是从所有者借出的共享引用,允许多条读取路径同时存在,本身可以复制。普通数据被共享借用期间,所有者也只能读。&mut T 是可变引用,可读可写,但必须独占对应值的访问权,因而不能复制。借用还在使用时,经由所有者的独立访问同样受约束。选参数类型时,只读打印用 &T,原地排序用 &mut T,接管值才用 T。
关联阅读:[[借用冻结所有权路径]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- References 用借用读取或修改容器 · 查看原书依据
the distinction between shared and mutable references as a way to enforce a multiple readers or single writer rule at compile time.
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第04章《References》|用借用读取或修改容器,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch04.xhtml#references-to-values`
- 结论依据:作者将两种借用概括为编译时的多读者或单写者,并明确这些权限约束也适用于所有者。
- 原始内容:the distinction between shared and mutable references as a way to enforce a multiple readers or single writer rule at compile time.