I am working through the Rust book, namely the minigrep project. There I came across the following snippet:
fn main() {
let args: Vec<String> = env::args().collect();
let (query, filename) = parse_config(&args);
// --snip--
}
fn parse_config(args: &[String]) -> (&str, &str) {
let query = &args[1];
let filename = &args[2];
(query, filename)
}
The confusing piece for me is args: &[String]
. If I replace it with args: &Vec<String>
, it also works. My guess is that &[String]
is a more general type annotation that matches not only &Vec<String>
, but also some other types. Is that correct? If so, what other types are matched by [T]
?