For the following code:
struct Config<'a> {
query: &'a str,
filename: &'a str,
case_sensitive: bool,
}
impl<'a> Config<'a> {
pub fn new(args: &'a [String]) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("not enough arguments");
}
let query = &args[1];
let filename = &args[2];
let case_sensitive = env::var("CASE_INSENSITIVE").is_err();
Ok(Config {
query,
filename,
case_sensitive,
})
}
}
Why impl<'a> Config<'a> {
is required, rather than impl Config<'a> {
?
What is the syntactic meaning of the first and second 'a
? I know 'a
is a lifetime annotation, but don't know why it's placed after both impl
and Config
. What does the first 'a
do and what does the second 'a
do?