I'm trying to access command line arguments. If the argument exists, do something, if not, do nothing. I have this code:
fn main() {
if let Some(a) = std::env::args().nth(2) {
let b = a;
}
println!("{}", a);
}
I am not able to access a
or b
outside of this scope:
error[E0425]: cannot find value `a` in this scope
--> src/main.rs:6:20
|
6 | println!("{}", a);
| ^ not found in this scope
How do I resolve this? Is there a better way to approach what I'm trying to do?
See Question&Answers more detail:os