知识卡片
Borrow要求等价表示
Borrow让拥有形式与借用形式可被同类泛型代码处理,常用于HashMap按借用键查找。它比AsRef有更强语义要求:拥有与借用表示的Eq、Ord、Hash行为应一致;只借某个字段视图通常应考虑AsRef。Borrow有自身类型的通用实现,不代表AsRef也有。
补充约束:AsRef官方说明,2026-10-27查阅。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 1. Types More Pointer Traits · 查看原书依据
Borrow and BorrowMut traits, which each have a single method (borrow and borrow_mut, respectively). This method has the same signature as the equivalent AsRef/AsMut trait methods. The key difference in intents between these traits is visible via the blanket implementations that the standard library provides. Given an arbitrary Rust reference &T, there is a b
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《More Pointer Traits》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u045-ch01-061)。
- 结论依据:原文在“Borrow and BorrowMut”附近的定义、例子或代码支撑本卡核心说明:Borrow<T>让拥有形式与借用形式可被同类泛型代码处理,常用于HashMap按借用键查找。边界按已读前提解释;示例未执行。
- 原始内容:Borrow and BorrowMut traits, which each have a single method (borrow and borrow_mut, respectively). This method has the same signature as the equivalent AsRef/AsMut trait methods. The key difference in intents between these traits is visible via the blanket implementations that the standard library provides. Given an arbitrary Rust reference &T, there is a b