-
Notifications
You must be signed in to change notification settings - Fork 178
Description
Right now --when no matching variant is found-- (parsing a string into an enum using the derived from_str) a constant string error is returned saying "Matching variant not found". There are two improvements that can be done on this:
-
Better default: A better default would probably be something like
"expected 'string1', 'string2', 'string3' or 'string4'". Even though it costs to iterate over the options, it doesn't matter, because it would only happen when no valid string is found. -
Custom error: The user should be able to specify a custom error message, something like:
#[derive(EnumString)]
#[strum(onerror="We like you, but can't understand what you wrote, please use 'string1' or 'string2'")
enum Foo {
#[strum(serialize="string1")]
Option1,
#[strum(serialize="string2")]
Option2,
}** special token: You could even provide a special token for the onerror keyword so that the user doesn't have to repeat the options all the time. Something like onerror="We like you, but can't understand what you wrote, please use {opts}".