pub trait Parameter:
Send
+ Sync
+ Debug {
Show 13 methods
// Required methods
fn name(&self) -> &str;
fn human_readable_name(&self) -> String;
fn nargs(&self) -> Nargs;
fn multiple(&self) -> bool;
fn is_eager(&self) -> bool;
fn expose_value(&self) -> bool;
fn required(&self) -> bool;
fn envvar(&self) -> Option<&[String]>;
fn help(&self) -> Option<&str>;
fn hidden(&self) -> bool;
fn get_metavar(&self) -> Option<String>;
fn get_help_record(&self) -> Option<(String, String)>;
// Provided method
fn param_type_name(&self) -> &str { ... }
}Expand description
A trait for command-line parameters (options and arguments).
This trait defines the common interface for all parameter types. Options and Arguments implement this trait with their specific behaviors.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
The primary name of the parameter.
For options, this is typically the long option name without dashes. For arguments, this is the argument name.
Sourcefn human_readable_name(&self) -> String
fn human_readable_name(&self) -> String
Human-readable name for errors and help text.
For options, this is usually the option flags (e.g., “–name / -n”). For arguments, this is typically the metavar in uppercase.
Sourcefn multiple(&self) -> bool
fn multiple(&self) -> bool
Whether this parameter can be specified multiple times.
When true, the parameter collects values into a list/tuple.
Sourcefn is_eager(&self) -> bool
fn is_eager(&self) -> bool
Whether this parameter should be processed before others.
Eager parameters (like --help and --version) are processed
first and can short-circuit command execution.
Sourcefn expose_value(&self) -> bool
fn expose_value(&self) -> bool
Whether this parameter’s value should be exposed in ctx.params.
When false, the parameter is still processed but its value is not stored in the context parameters.
Sourcefn required(&self) -> bool
fn required(&self) -> bool
Whether this parameter is required.
Required parameters must be provided via CLI, environment, or default.
Sourcefn envvar(&self) -> Option<&[String]>
fn envvar(&self) -> Option<&[String]>
Get environment variable name(s) for this parameter.
Returns None if no environment variables are configured.
Multiple environment variables can be specified; the first
non-empty value is used.
Whether this parameter is hidden from help.
Sourcefn get_metavar(&self) -> Option<String>
fn get_metavar(&self) -> Option<String>
Get the metavar for help text (e.g., “FILE”, “TEXT”).
If not explicitly set, the type’s metavar is used.
Sourcefn get_help_record(&self) -> Option<(String, String)>
fn get_help_record(&self) -> Option<(String, String)>
Generate help record for formatting.
Returns a tuple of (option_string, help_string) for help display,
or None if this parameter should not appear in help.
Provided Methods§
Sourcefn param_type_name(&self) -> &str
fn param_type_name(&self) -> &str
Get the parameter type name (for error messages).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".