知识卡片

普通读书笔记卡 · 6074.f.9

生命周期标注表达引用关系

理解等级:中级

签名中的’a说明引用之间的有效性约束,不会让对象活得更久。find若返回haystack内的切片,应把输出与haystack关联;needle可使用独立生命周期。若误把两输入都绑定同名,就可能无意缩短输出可用范围,限制本来安全的调用。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 3. Concepts Algebra of Lifetimes · 查看原书依据

      Algebra of Lifetimes Although lifetimes are ubiquitous when dealing with references in Rust, you don’t get to specify them in any detail—there’s no way to say, “I’m dealing with a lifetime that extends from line 17 to line 32 of ref.rs.” Instead, your code refers to lifetimes with arbitrary names, conventionally 'a, 'b, 'c, …, and the compiler has its own in

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Algebra of Lifetimes》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u081-ch03-005)。 - 结论依据:原文在“Algebra of Lifetimes”附近的定义、例子或代码支撑本卡核心说明:签名中的'a说明引用之间的有效性约束,不会让对象活得更久。边界按已读前提解释;示例未执行。 - 原始内容:Algebra of Lifetimes Although lifetimes are ubiquitous when dealing with references in Rust, you don’t get to specify them in any detail—there’s no way to say, “I’m dealing with a lifetime that extends from line 17 to line 32 of ref.rs.” Instead, your code refers to lifetimes with arbitrary names, conventionally 'a, 'b, 'c, …, and the compiler has its own in