[][src]Crate parse_arg

This crate provides traits and implementations for parsing command-line arguments. The core of the crate is ParseArg trait. It works much like FromStr trait, but with these differences:

  • It operates on &OsStr instead of &str, thus allowing wider range of possible inputs.
  • It provides parse_owned_arg() method which can be specialized to avoid allocations.
  • It requires the implementor to provide describe_type() to print human-readable description. of expected input.
  • It requires the error type to implement Display in order to enable user-friendly interface.

Further, the crate provides ParseArgFromStr trait, which causes any type implementing it to auto-implement ParseArg trait. This is handy when implementing ParseArg for types that already have FromStr implemented, so that boilerplate is reduced.

Structs

ShortIter

An iterator of short options.

Enums

ParseArgError

Possible error when parsing certain arguments.

ValueError

Error that can occur durin parsing command-line argument.

Traits

Arg

A type that can be parsed.

ParseArg

Defines an interface for types that can be created by parsing command-line argument.

ParseArgFromStr

Shorthand for implementing ParseArg for types that already implement FromStr.

Functions

iter_short

Creates an iterator of short arguments if the input is in the form -abc.

match_arg

Checks whether given arg matches the name or begins with name= and parses it appropriately.