pub trait MatchArg:
Sized
+ Copy
+ 'static {
const CHOICES: &'static [&'static str];
const ALIASES: &'static [MatchArgAlias] = _;
// 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§
Provided Associated Constants§
Sourceconst ALIASES: &'static [MatchArgAlias] = _
const ALIASES: &'static [MatchArgAlias] = _
Other spellings of a choice: MatchArgAlias::new("grey", "gray") lets a user write "grey" for the choice
"gray" (#1843).
An alias selects its choice only when typed in full: a prefix matches
the choices alone, so "gr" stays the prefix of "gray" it was. Every
matcher reads it, the generated wrapper’s check and the Rust side
alike (match_arg_from_sexp, match_arg_param,
match_arg_vec_from_sexp element by element, the Either arm).
Every error that lists the choices names the listed aliases after
them, 'color' should be one of "red", "gray", "blue" (or "grey" for "gray"), on both sides (#2148). An alias built with
MatchArgAlias::unlisted is matched the same way and named by no
error. The R formal, the usage and the @param line list CHOICES
only.
#[derive(MatchArg)] fills it from #[match_arg(alias = "...")] on a
variant (listed = false for an unlisted one). A hand-written impl
lists its aliases here, not in from_choice,
which the R-side check never reaches. The wrappers writer refuses, for
a type used as a match_arg parameter, an alias that is empty, "NA",
a choice, repeated, or a prefix of a choice other than its own, and a
target that is not a choice.
Required Methods§
Sourcefn from_choice(choice: &str) -> Option<Self>
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. An
alias is not a choice: ALIASES maps it.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".