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
的生命周期参数struct,这就是编译器提示类型参数“隐藏”并建议您为 args
提供完整类型的原因通过写作 ArgMatches<'_>
使您的代码更加明确和清晰。
关于rust - 如何解决 "indicate anonymous lifetime <' _>”错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66171697/