Trait structconf::StructConf[][src]

pub trait StructConf {
    fn parse(app: App<'_>, path: &str) -> Result<Self, Error>
    where
        Self: Sized
;
fn parse_args(app: App<'_>) -> ArgMatches;
fn parse_args_from<I, T>(app: App<'_>, iter: I) -> ArgMatches
    where
        I: IntoIterator<Item = T>,
        T: Into<OsString> + Clone
;
fn parse_file(args: &ArgMatches, path: &str) -> Result<Self, Error>
    where
        Self: Sized
;
fn write_file(&self, path: &str) -> Result<(), Error>; }
Expand description

This trait implements the methods available after using #[derive(StructConf)].

The priority followed for the configuration is “arguments > config file > default values”.

Required methods

Instantiate the structure from both the argument parser and the config file, falling back to the default values. Equivalent to calling parse_args and then parse_file.

The path argument is where the config file will be. If it doesn’t exist, it will be created, and a message to stderr will be printed.

Parses only the arguments with clap. This is useful for a --config-file argument to allow the user to choose the config file location.

This is equivalent to parse_args_from(..., &mut std::env::args()).

Parses only the arguments with clap from an iterator.

The config file is read after parsing the arguments, and the struct is initialized with the default values taken into account.

The path argument is where the config file will be. If it doesn’t exist, it will be created, and a message to stderr will be printed.

This also serves as a function to refresh the config file values.

Writes the structure’s values into a config file, except for those that are wrapped by Option and whose value is None.

Implementors