2019-08-31 12:48:26 +05:30
|
|
|
use rust_decimal::Error as DecimalError;
|
2018-03-24 15:46:28 +01:00
|
|
|
use std::error::Error;
|
|
|
|
|
use std::fmt;
|
2018-05-22 22:57:51 +02:00
|
|
|
use std::num;
|
2018-03-24 15:46:28 +01:00
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2018-03-24 20:17:17 +01:00
|
|
|
pub enum ParameterScanError {
|
2018-03-24 15:46:28 +01:00
|
|
|
ParseIntError(num::ParseIntError),
|
2019-08-31 12:48:26 +05:30
|
|
|
ParseDecimalError(DecimalError),
|
2018-03-24 15:46:28 +01:00
|
|
|
EmptyRange,
|
|
|
|
|
TooLarge,
|
2019-08-22 00:50:20 +05:30
|
|
|
ZeroStep,
|
2019-08-31 12:48:26 +05:30
|
|
|
StepRequired,
|
2018-03-24 15:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-24 20:17:17 +01:00
|
|
|
impl From<num::ParseIntError> for ParameterScanError {
|
|
|
|
|
fn from(e: num::ParseIntError) -> ParameterScanError {
|
|
|
|
|
ParameterScanError::ParseIntError(e)
|
2018-03-24 15:46:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
2018-09-09 14:10:36 +01:00
|
|
|
write!(f, "{}", self.description())
|
2018-03-24 15:46:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 20:17:17 +01:00
|
|
|
impl Error for ParameterScanError {
|
2018-03-24 15:46:28 +01:00
|
|
|
fn description(&self) -> &str {
|
2018-09-09 14:10:36 +01:00
|
|
|
match *self {
|
|
|
|
|
ParameterScanError::ParseIntError(ref e) => e.description(),
|
2019-08-31 12:48:26 +05:30
|
|
|
ParameterScanError::ParseDecimalError(ref e) => e.description(),
|
2018-09-09 14:10:36 +01:00
|
|
|
ParameterScanError::EmptyRange => "Empty parameter range",
|
|
|
|
|
ParameterScanError::TooLarge => "Parameter range is too large",
|
2019-08-22 00:50:20 +05:30
|
|
|
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"
|
|
|
|
|
}
|
2018-09-09 14:10:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[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 {
|
2018-09-09 14:10:36 +01:00
|
|
|
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",
|
|
|
|
|
}
|
2018-03-24 15:46:28 +01:00
|
|
|
}
|
|
|
|
|
}
|