diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-01-07 12:02:56 +0000 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-01-07 12:02:56 +0000 |
commit | 31a0cb956c7c4d8a0fb895506cc5a4a89309bdfd (patch) | |
tree | 484f6fe430b137e32f04a60eff919140d28a8ad2 | |
parent | bf6dd8ec388512f5e56b888fb0407f6e83f604c5 (diff) | |
download | nitrocli-31a0cb956c7c4d8a0fb895506cc5a4a89309bdfd.tar.gz nitrocli-31a0cb956c7c4d8a0fb895506cc5a4a89309bdfd.tar.bz2 |
arg_util: Change Err type in FromStr implementation
structopt requires that FromStr::Err implements std::fmt::Display.
Therefore we now return a String that contains a list of allowed values.
-rw-r--r-- | src/arg_util.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/arg_util.rs b/src/arg_util.rs index 56f8758..b96f653 100644 --- a/src/arg_util.rs +++ b/src/arg_util.rs @@ -107,14 +107,23 @@ macro_rules! enum_int { } impl ::std::str::FromStr for $name { - type Err = (); + type Err = ::std::string::String; fn from_str(s: &str) -> ::std::result::Result<Self, Self::Err> { match s { $( $str => Ok($name::$var), )* - _ => Err(()), + _ => Err( + format!( + "expected one of {}", + $name::all_variants() + .iter() + .map(::std::convert::AsRef::as_ref) + .collect::<::std::vec::Vec<_>>() + .join(", "), + ) + ) } } } |