Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Type aware command line parsing in Rust
Rationale
While getopts is available for the Rust platform, it is not very practical, since the generated map of properties must be checked for existence, then cast to the required types, leading to a lot of options and pattern matching.
Typedopts is available on crates.io
Usage
With this library, you can define a structure representing the possible parameters, deriving Decodable, and parse it directly:
extern crate getopts;
extern crate typedopts;
extern crate "rustc-serialize" as rustc_serialize;
use Options;
use os;
use ;
use Decodable;
If the decode function finds the correct arguments and is able to parse them, you will get an instance of the structure you need in the Result. Otherwise, you receive an enum of errors:
- UnimplementedDecoder: required but should not happen (if you find a use case where you encounter it, please open an issue)
- MissingField: the option was not found. If you use the reqopt function from getopts, it would warn you before typedopts
- ExpectedType: the option's value is not the one needed
Unless you want to handle the errors yourself, you can use directly the to__err__msg function.
Examples
Most types can be handled by the library, as long as they can derive from Decodable. Integers, Unsigned integers, floating point numbers, booleans, characters, strings are easy to do.
Enumerations will require that you define them as Decodable too:
/* ... */
if
Options are also supported:
/* ... */
match decoded.option
Handling --help with required options
By default, if you define any options as required, getopts will need them everytime, even when you just want to display the help and usage instructions.
A way to fix it is available in the examples/getopt.rs file. Basically, you define a function to generate the getopts instance (trust me on this, it will avoid move problems):
extern crate getopts;
extern crate typedopts;
extern crate "rustc-serialize" as rustc_serialize;
use os;
use Options;
use ;
use Decodable;
Then you define the usage function (from the getopts documentation):
Then, in your argument parsing function, you will parse the options two times, one to detect the help argument, another one for the main arguments.
If the help argument is found, show the help then return immediately, otherwise, parse arguments normally.