Struct kripher::options::Options
[−]
[src]
pub struct Options { pub version: bool, pub encode: bool, pub decode: bool, pub output: Option<String>, pub rest: Vec<String>, }
Stores the options so our programs knows what to do.
Normaly you obtain this struct as a result of parsing the command line arguments passed to the program.
In this program we have only three different flags that can be activated.
We store this information with three bool
s. The remaining command line
arguments after the parsing are stored in a new Vec<String>
named
Options::rest
.
Fields
version: bool
Whether the --version
flag was activated or not.
encode: bool
Whether the --encode
flag was activated or not.
decode: bool
Whether the --decode
flag was activated or not.
output: Option<String>
If the --output
option was set, here is the program's output filename
stored. Otherwise None
.
rest: Vec<String>
The remaining command line arguments that weren't parsed.
Methods
impl Options
[src]
fn from_args<A: Iterator<Item = String>>(args: A) -> Options
Takes a vector of String
and creates a Options
struct.
Usually you want to parse std::env::args()
to detect when the
different command line flags were activated. Note that normally the
first element to appear in std::env::args()
is the executable name,
so you should skip it.
Examples
use kripher::options::Options; use std::env; let args = env::args().skip(1); let o = Options::from_args(args); if o.version { println!("The --version flag was active.") }