I have a match statement where I want to print the error, if it occurs. But, it seems it wont allow it due to the generic type:
match get_numeral(&str_inp).parse::<T>() {
Ok(rslt) => {
if rslt >= val_min && rslt <= val_max {
str_inp = rslt.to_string();
finish = true;
}
}
Err(e) => (println!("{}", e)),
}
With the preceding code, the following error is displayed:
137 | Err(e)=> (println!("{}",e)),
| ^ `<T as std::str::FromStr>::Err` cannot be formatted with the default
formatter
What am I missing here?
I did notice the following hints:
= help: the trait `std::fmt::Display` is not implemented for `<T as std::str::FromStr>::Err`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= help: consider adding a `where <T as std::str::FromStr>::Err: std::fmt::Display` bound
= note: required by `std::fmt::Display::fmt`
My function definition looks like:
fn expect_val<T>(val_min: T, val_max: T, accept: Vec<String>) -> String
where
T: std::str::FromStr + PartialOrd + ToString,