知识卡片
签名中的生命周期省略
读取省略签名时,先替每个被省略的输入生命周期填入独立参数。输入只有一个生命周期时,未标注的输出沿用它。方法以引用接收 self 时,输出沿用接收者的生命周期,所以用短期查询词筛选列表,结果仍能跟随列表的借用。多路输入又没有引用接收者时,要显式注明返回借用从哪一方取得有效期。想表达不同的关联,也可以写出完整标注。
关联阅读:[[返回引用沿用输入约束]]、[[独立借用用独立生命周期]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- References 按省略规则读出签名的借用来源 · 查看原书依据
If there’s only a single lifetime that appears among your function’s parameters, then Rust assumes any lifetimes in your return value must be that one:
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第04章《References》|按省略规则读出签名的借用来源,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch04.xhtml#omitting-lifetime-parameters`
- 结论依据:原文依次给出不同输入各自省略、单一输入向输出传递,以及接收者优先的展开示例。
- 原始内容:If there’s only a single lifetime that appears among your function’s parameters, then Rust assumes any lifetimes in your return value must be that one: