From 9a064b7a8f23a52d0420daa2571686a8b83d7c23 Mon Sep 17 00:00:00 2001 From: Andrii Radyk Date: Sun, 15 Dec 2019 23:47:53 +0100 Subject: [PATCH] remove deprecated Error::description --- src/hyperfine/error.rs | 35 ++++++++++++++--------------------- src/main.rs | 9 ++++----- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/hyperfine/error.rs b/src/hyperfine/error.rs index bbe388f..a2627f8 100644 --- a/src/hyperfine/error.rs +++ b/src/hyperfine/error.rs @@ -27,27 +27,24 @@ impl From for ParameterScanError { impl fmt::Display for ParameterScanError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.description()) - } -} - -impl Error for ParameterScanError { - fn description(&self) -> &str { match *self { - ParameterScanError::ParseIntError(ref e) => e.description(), - ParameterScanError::ParseDecimalError(ref e) => e.description(), - ParameterScanError::EmptyRange => "Empty parameter range", - ParameterScanError::TooLarge => "Parameter range is too large", - ParameterScanError::ZeroStep => "Zero is not a valid parameter step", - ParameterScanError::StepRequired => { + ParameterScanError::ParseIntError(ref e) => write!(f, "{}", e), + ParameterScanError::ParseDecimalError(ref e) => write!(f, "{}", e), + ParameterScanError::EmptyRange => write!(f, "Empty parameter range"), + ParameterScanError::TooLarge => write!(f, "Parameter range is too large"), + ParameterScanError::ZeroStep => write!(f, "Zero is not a valid parameter step"), + ParameterScanError::StepRequired => write!( + f, "A step size is required when the range bounds are \ floating point numbers. The step size can be specified \ with the '--parameter-step-size' parameter" - } + ), } } } +impl Error for ParameterScanError {} + #[derive(Debug)] pub enum OptionsError { RunsBelowTwo, @@ -56,15 +53,11 @@ pub enum OptionsError { impl fmt::Display for OptionsError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.description()) - } -} - -impl Error for OptionsError { - fn description(&self) -> &str { match *self { - OptionsError::EmptyRunsRange => "Empty runs range", - OptionsError::RunsBelowTwo => "Number of runs below two", + OptionsError::EmptyRunsRange => write!(f, "Empty runs range"), + OptionsError::RunsBelowTwo => write!(f, "Number of runs below two"), } } } + +impl Error for OptionsError {} diff --git a/src/main.rs b/src/main.rs index e3496ca..3181f0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use std::cmp; use std::env; -use std::error::Error; use std::io; use atty::Stream; @@ -58,7 +57,7 @@ fn main() { let res = match options { Ok(ref opts) => run(&commands, &opts), - Err(ref e) => error(e.description()), + Err(ref e) => error(&e.to_string()), }; match res { @@ -73,11 +72,11 @@ fn main() { if let Err(e) = ans { error(&format!( "The following error occurred while exporting: {}", - e.description() + e )); } } - Err(e) => error(e.description()), + Err(e) => error(&e.to_string()), } } @@ -206,7 +205,7 @@ fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec> { let step_size = matches.value_of("parameter-step-size"); match get_parameterized_commands(command_strings, args, step_size) { Ok(commands) => commands, - Err(e) => error(e.description()), + Err(e) => error(&e.to_string()), } } else if let Some(mut args) = matches.values_of("parameter-list") { let param_name = args.next().unwrap();