知识卡片
匿名生命周期提示隐藏借用
ReferenceHolder<‘_>明确提示返回值含有借用关系,同时省去无需重复引用的寿命名字。它让接口比直接写ReferenceHolder更易读,具体关系仍由规则与上下文推断。’_不会创建任意长寿引用,也不替代需要明确输入输出关系的具名参数。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Anonymous Lifetimes · 查看原书依据
Anonymous Lifetimes When it’s not possible to stick to data structures that own their contents, the data structure will necessarily end up with a lifetime parameter, as described in the previous section. This can create a slightly unfortunate interaction with the lifetime elision rules described earlier in the Item. For example, consider a function that retu
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Anonymous Lifetimes》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u086-ch03-012)。
- 结论依据:原文在“Anonymous Lifetimes”附近的定义、例子或代码支撑本卡核心说明:ReferenceHolder<'_>明确提示返回值含有借用关系,同时省去无需重复引用的寿命名字。边界按已读前提解释;示例未执行。
- 原始内容:Anonymous Lifetimes When it’s not possible to stick to data structures that own their contents, the data structure will necessarily end up with a lifetime parameter, as described in the previous section. This can create a slightly unfortunate interaction with the lifetime elision rules described earlier in the Item. For example, consider a function that retu