diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-01-07 12:02:56 +0000 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-01-08 09:20:34 -0800 |
commit | 30e7ed5ff70766ea4a7de6761d29e012a15f02c9 (patch) | |
tree | 065cab14a14817db142bf63ece222b99ef946549 | |
parent | b1725639a21a8661c8e8dfe30811b650abf028b0 (diff) | |
download | nitrocli-30e7ed5ff70766ea4a7de6761d29e012a15f02c9.tar.gz nitrocli-30e7ed5ff70766ea4a7de6761d29e012a15f02c9.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-- | nitrocli/src/arg_util.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/nitrocli/src/arg_util.rs b/nitrocli/src/arg_util.rs index 3e4ba85..5980f48 100644 --- a/nitrocli/src/arg_util.rs +++ b/nitrocli/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(", "), + ) + ) } } } |