I am trying to learn Rust, and am trying to write a simple program that takes arguments from the command line, to get used to some basic concepts. The code I wrote to handle the arguments, fails, and I feel like I am missing some basic concept.
fn process_args(args: Vec<String>) {
let my_string: String = String::from("--verbose");
for item in &args[1..] {
match item{
my_string=>do_something_with_argument(),
_=>println!("unexpected argument {item}"),
}
}
}
Where vscode tells me that the 'my_string', variable is unused. I also tried this version:
fn process_args(args: Vec<String>) {
for item in &args[1..] {
match item{
"--verbose"=>do_something_with_argument(),
_=>println!("unexpected argument {item}"),
}
}
}
which fails because the string literal cannot be matched with a string, then I tried:
fn process_args(args: Vec<String>) {
for item in &args[1..] {
match item{
String::from("--verbose")=>do_something_with_argument(),
_=>println!("unexpected argument {item}"),
}
}
}
Which also does not work.
What am I missing. I feel like they all should work.