Files
hyperfine/src/hyperfine/error.rs
T

70 lines
2.0 KiB
Rust
Raw Normal View History

2019-08-31 12:48:26 +05:30
use rust_decimal::Error as DecimalError;
use std::error::Error;
use std::fmt;
2018-05-22 22:57:51 +02:00
use std::num;
#[derive(Debug)]
2018-03-24 20:17:17 +01:00
pub enum ParameterScanError {
ParseIntError(num::ParseIntError),
2019-08-31 12:48:26 +05:30
ParseDecimalError(DecimalError),
EmptyRange,
TooLarge,
ZeroStep,
2019-08-31 12:48:26 +05:30
StepRequired,
}
2018-03-24 20:17:17 +01:00
impl From<num::ParseIntError> for ParameterScanError {
fn from(e: num::ParseIntError) -> ParameterScanError {
ParameterScanError::ParseIntError(e)
}
}
2019-08-31 12:48:26 +05:30
impl From<DecimalError> for ParameterScanError {
fn from(e: DecimalError) -> ParameterScanError {
ParameterScanError::ParseDecimalError(e)
}
}
2018-03-24 20:17:17 +01:00
impl fmt::Display for ParameterScanError {
2019-05-07 11:55:38 +02:00
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.description())
}
}
2018-03-24 20:17:17 +01:00
impl Error for ParameterScanError {
fn description(&self) -> &str {
match *self {
ParameterScanError::ParseIntError(ref e) => e.description(),
2019-08-31 12:48:26 +05:30
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",
2019-09-01 16:00:53 +05:30
ParameterScanError::StepRequired => {
"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"
}
}
}
}
#[derive(Debug)]
pub enum OptionsError {
RunsBelowTwo,
EmptyRunsRange,
}
impl fmt::Display for OptionsError {
2019-05-07 11:55:38 +02:00
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",
}
}
}