Crate parse_arg

source ·
Expand description

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.

Enums

Possible error when parsing certain arguments.
Error that can occur durin parsing command-line argument.

Traits

A type that can be parsed.
Defines an interface for types that can be created by parsing command-line argument.
Shorthand for implementing ParseArg for types that already implement FromStr.

Functions

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