pub trait TypeConverter:
Debug
+ Send
+ Sync {
type Value;
// Required methods
fn name(&self) -> &str;
fn convert(&self, value: &str) -> Result<Self::Value, String>;
// Provided methods
fn get_metavar(&self) -> Option<String> { ... }
fn get_missing_message(&self) -> Option<String> { ... }
fn split_envvar_value(&self, value: &str) -> Vec<String> { ... }
fn shell_complete(&self, _incomplete: &str) -> Vec<CompletionItem> { ... }
fn is_composite(&self) -> bool { ... }
fn arity(&self) -> usize { ... }
}Expand description
Trait for parameter types that convert and validate command-line values.
Each type must define how to convert a string value from the command line into the appropriate Rust type.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn get_metavar(&self) -> Option<String>
fn get_metavar(&self) -> Option<String>
Returns the metavar for this type (used in help text).
For example, INT might return "INTEGER".
Sourcefn get_missing_message(&self) -> Option<String>
fn get_missing_message(&self) -> Option<String>
Returns an optional message when a required value is missing.
Sourcefn split_envvar_value(&self, value: &str) -> Vec<String>
fn split_envvar_value(&self, value: &str) -> Vec<String>
Split an environment variable value into multiple values.
By default, splits on whitespace. Path-based types override this to split on the platform’s path separator.
Sourcefn shell_complete(&self, _incomplete: &str) -> Vec<CompletionItem>
fn shell_complete(&self, _incomplete: &str) -> Vec<CompletionItem>
Returns shell completion items for the given incomplete value.
Most types return an empty list; types like Choice and Path
can provide completions.
Sourcefn is_composite(&self) -> bool
fn is_composite(&self) -> bool
Whether this type is a composite type (like Tuple).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".