rust - 如何解决“指示匿名生命周期<'_>”错误?
问题描述
warning: hidden lifetime parameters in types are deprecated
--> asd/src/app/qwe.rs:88:45
|
88 | fn add_meta_from_args(&mut self, args: &ArgMatches) -> AppRun {
| ^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
我应该在哪里指定这个匿名生命周期?我也不是很了解它的必要性。如果参数是借用的,为什么它也需要生命周期?
解决方案
其中的ArgMatches<'a>
结构在clap
生命周期内是通用的。您没有在函数中写出完整类型,args
因为您省略了ArgMatches
结构的生命周期参数,这就是编译器抱怨类型参数“隐藏”并建议您args
通过写入ArgMatches<'_>
来提供完整类型的原因使您的代码更加明确和清晰。
推荐阅读
- python - 读取 csv 文件的标题并查看它是否与字典键匹配,然后将该键的值写入行
- c# - 在 Asp.Net API 中使用多个 Get()
- javascript - 在文本中查找准确的单词,不包括引用的单词
- html - 如何在html中的输入类型日期中添加颜色
- reactjs - 从没有 ReactDOM.findDOMNode 的 React 子元素获取 DOM 节点
- c# - 我在情节提要中创建了一个按钮事件,但出现错误
- python - 在 Mock 对象上使用方法
- javascript - WP Gutenberg InnerBlocks 不保存
- r - 如何在 RStudio 中安装 R 包期间抑制更新加载的包窗口?
- javascript - EOSJS & Scatter - 无法读取未定义的属性'Symbol(Symbol.iterator)'