How can I enter command line arguments in Rust using docopts? I'd like to simply be able to enter a u8 in a vector and parse it with docopts.
Asked
Active
Viewed 184 times
-2
-
2Welcome to Stack Overflow! In the interest of getting better answers, please take care to [ask better questions](http://stackoverflow.com/help/how-to-ask). In this case, you should show some example code of what you tried. Or maybe some search results for things you've looked up but don't understand. At the very least, you could write some example code (or pseudocode) that better explains what you want to do. – Shepmaster Mar 21 '15 at 00:45
1 Answers
1
You can use the std::env::args
method to obtain an iterator. Then, you can use .collect
on the iterator to get a vector of String
s.
use std::env;
fn main () {
let args: Vec<String> = env::args().collect();
println!("{:?}", args);
}
Example output:
simon@Simon-Desktop:~$ rustc t.rs
simon@Simon-Desktop:~$ ./t abc def
["./t", "abc", "def"]

SBSTP
- 3,479
- 6
- 30
- 41