知识卡片
搜索结果借自输入正文
签名 search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> 把切片有效期系在正文上。query 的借用与输出寿命独立。省略标注时两个输入具有各自的借用,编译器无法判断返回切片来自哪个输入。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- I/O 项目:构建命令行程序 Developing the Library’s Functionality with Test-Driven Development · 查看原书依据
Notice that we need to define an explicit lifetime 'a in the signature of search and use that lifetime with the contents argument and the return value. Recall in Chapter 10 that the lifetime parameters specify which argument lifetime is connected to the lifetime of the return value.
参考来源
- 位置:《The Rust Programming Language(第2版)》第12章 I/O 项目:构建命令行程序(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c12.xhtml`,块 0195)
- 结论依据:原文明确输出向量的切片来自 `contents`。
- 原始内容:Notice that we need to define an explicit lifetime 'a in the signature of search and use that lifetime with the contents argument and the return value. Recall in Chapter 10 that the lifetime parameters specify which argument lifetime is connected to the lifetime of the return value.