知识卡片
省略生命周期仍保留约束
省略不表示没有生命周期。每个输入引用先取得独立参数;若只有一个输入寿命,输出通常与它关联;方法有&self或&mut self时,输出通常与接收者关联。若函数实际返回另一个参数中的引用,就应显式标注关系,不能让默认规则替代真实借用来源。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Lifetime Elision Rules · 查看原书依据
Lifetime Elision Rules In addition to the “one in, one out” elision rule described in “Algebra of Lifetimes”, there are two other elision rules that mean that lifetime names can be omitted. The first occurs when there are no references in the outputs from a function; in this case, each of the input references automatically gets its own lifetime, different fr
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Lifetime Elision Rules》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u082-ch03-007)。
- 结论依据:原文在“Lifetime Elision Rules”附近的定义、例子或代码支撑本卡核心说明:省略不表示没有生命周期。边界按已读前提解释;示例未执行。
- 原始内容:Lifetime Elision Rules In addition to the “one in, one out” elision rule described in “Algebra of Lifetimes”, there are two other elision rules that mean that lifetime names can be omitted. The first occurs when there are no references in the outputs from a function; in this case, each of the input references automatically gets its own lifetime, different fr