问题
Consider the following code:
extern crate clap;
use clap::{App};
use std::io;
fn parse_argv() -> &'static clap::ArgMatches {
return App::new("example")
.get_matches()
}
fn main() -> io::Result<()> {
let matches = parse_argv();
Ok(())
}
This is the error:
error[E0106]: missing lifetime specifier
--> src/main.rs:6:29
|
6 | fn parse_argv() -> &'static clap::ArgMatches {
| ^^^^^^^^^^^^^^^^ help: consider giving it a 'static lifetime: `clap::ArgMatches + 'static`
|
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
What is the problem here and how do I solve it? I think I did what compiler asked for, but the error won't disappear.
回答1:
I got an answer on #rust-beginners IRC channel:
13:10:17 drager | d33tah: I suspect that ArgMatches actually wants the lifetime, so ArgMatches<'static> in this case
So, the solution was to change the function signature to:
fn parse_argv() -> clap::ArgMatches<'static> {
来源:https://stackoverflow.com/questions/54217705/errore0106-missing-lifetime-specifier-despite-it-being-set