Skip to main content

AnyTypeConverter

Trait AnyTypeConverter 

Source
pub trait AnyTypeConverter: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn convert_any(
        &self,
        value: &str,
    ) -> Result<Box<dyn Any + Send + Sync>, String>;
    fn convert_multi(
        &self,
        values: &[String],
    ) -> Result<Box<dyn Any + Send + Sync>, String>;
    fn get_metavar(&self) -> Option<String>;
    fn split_envvar_value(&self, value: &str) -> Vec<String>;
    fn shell_complete(&self, incomplete: &str) -> Vec<CompletionItem>;
}
Expand description

A type-erased wrapper for TypeConverter that stores converted values as Box<dyn Any>.

This allows arguments to work with any TypeConverter, not just those returning String.

Required Methods§

Source

fn name(&self) -> &str

Returns the descriptive name of this type.

Source

fn convert_any(&self, value: &str) -> Result<Box<dyn Any + Send + Sync>, String>

Convert a string value to the target type, returning as Box.

Source

fn convert_multi( &self, values: &[String], ) -> Result<Box<dyn Any + Send + Sync>, String>

Convert multiple string values to the target type, returning as Box.

By default this returns a Vec of the underlying type.

Source

fn get_metavar(&self) -> Option<String>

Returns the metavar for this type.

Source

fn split_envvar_value(&self, value: &str) -> Vec<String>

Split an environment variable value into multiple values.

Source

fn shell_complete(&self, incomplete: &str) -> Vec<CompletionItem>

Returns shell completion items for the given incomplete value.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> AnyTypeConverter for T
where T: TypeConverter + Send + Sync, T::Value: Send + Sync + 'static,