From 31a0cb956c7c4d8a0fb895506cc5a4a89309bdfd Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 7 Jan 2020 12:02:56 +0000 Subject: 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. --- src/arg_util.rs | 13 +++++++++++-- 1 file 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 { 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(", "), + ) + ) } } } -- cgit v1.2.3