Skip to main content

MatchArg

Trait MatchArg 

Source
pub trait MatchArg:
    Sized
    + Copy
    + 'static {
    const CHOICES: &'static [&'static str];

    // Required methods
    fn from_choice(choice: &str) -> Option<Self>;
    fn to_choice(self) -> &'static str;
}
Expand description

Trait for enum types that support match.arg-style string conversion.

Implementors provide a fixed set of choice strings and bidirectional conversion between enum variants and their string representations.

Use #[derive(MatchArg)] to auto-generate this implementation.

Required Associated Constants§

Source

const CHOICES: &'static [&'static str]

The canonical choice strings, in variant declaration order.

The first choice is the default when the R argument is NULL.

Required Methods§

Source

fn from_choice(choice: &str) -> Option<Self>

Convert a choice string to the corresponding enum variant.

Returns None if the string doesn’t match any choice exactly.

Source

fn to_choice(self) -> &'static str

Convert the enum variant to its canonical choice string.

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.

Implementors§