How to get command line arguments in Rust?
Hello everyone! I just started learning Rust and encountered what seems like a simple task — I need to pass parameters to my program when running from the command line. For example, I want to write an image conversion utility that takes the path to the source file and the path to save the result.
I expected Rust to have something like `sys.argv` from Python or `process.argv` from Node.js, but I can't find a direct equivalent. Here's what I tried:
```rust
fn main() {
let args = std::env::args();
println!("Arguments: {:?}", args);
}
```
But the console prints something strange like `Args { inner: [...] }` instead of a list of strings. I want to get a simple array of strings so I can access them by index: `args[0]` (program name), `args[1]` (first argument), and so on.
No answers yet.
Log in to leave an answer
Blogs