I want the user to pass in command-line arguments to a simple function I've written in Rust. I know that I can use int::from_str(args[1])
to convert, but this returns an Option<int>
, which means in order to pass it into a function that takes an int
, like the one below, I have to use a match
statement. But with n arguments, there are 2^n possibilities. Writing a series of nested match
statements with something would be terrible. It would be ideal if there were a way to do something like:
// will return either Some(int) or None
let start = int::from_str(args[1]), end = int::from_str(args[2]);
if typeof(start) == Some && typeof(end) == Some {
println(fmt!("You entered: %d, %d", start, end);
} else {
println("Error with arguments.");
}
Is there any such method? That lets me test which member of an enum something is besides match
?