pub trait StructConf {
// Required methods
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§
Sourcefn parse(app: App<'_>, path: &str) -> Result<Self, Error>where
Self: Sized,
fn parse(app: App<'_>, path: &str) -> Result<Self, Error>where
Self: Sized,
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.
Sourcefn parse_args(app: App<'_>) -> ArgMatches
fn parse_args(app: App<'_>) -> ArgMatches
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())
.
Sourcefn parse_args_from<I, T>(app: App<'_>, iter: I) -> ArgMatches
fn parse_args_from<I, T>(app: App<'_>, iter: I) -> ArgMatches
Parses only the arguments with clap from an iterator.
Sourcefn parse_file(args: &ArgMatches, path: &str) -> Result<Self, Error>where
Self: Sized,
fn parse_file(args: &ArgMatches, path: &str) -> Result<Self, Error>where
Self: Sized,
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.