← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6074.f.9.j · 生成模型:未记录

省略规则从签名定归属

理解等级:中级

没有显式标注时,每个省略的输入引用首先得到独立生命周期。恰有一个输入生命周期时,它传给所有省略的输出借用;有多个输入且存在 &self 或 &mut self 时,输出使用接收者的借用范围。剩余歧义需要显式标注,编译器不会猜测。

相关卡片 [[返回借用受共同范围约束]]、[[借用字段约束容器使用期]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第10章 泛型类型、trait 与生命周期(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c10.xhtml`,块 0292) - 结论依据:原文说明三条规则分别适用于输入与输出以及未决时报告错误,后续用两例演算。 - 原始内容:The compiler uses three rules to figure out the lifetimes of the references when there aren’t explicit annotations. The first rule applies to input lifetimes, and the second and third rules apply to output lifetimes. If the compiler gets to the end of the three rules and there are still references for which it can’t figure out lifetimes, the compiler will stop with an error.