error.rs
This file
Path
src/error.rs
92 lines · 3.1 KiB · Rust
Last changed by
Re-order importsDavid Peterbefore adoption9df6174
History of this fileTake it
1use std::error::Error;2use std::fmt;3use std::num;4use std::num::ParseIntError;56use rust_decimal::Error as DecimalError;78#[derive(Debug)]9pub enum ParameterScanError {10 ParseIntError(num::ParseIntError),11 ParseDecimalError(DecimalError),12 EmptyRange,13 TooLarge,14 ZeroStep,15 StepRequired,16 UnexpectedCommandNameCount(usize, usize),17}1819impl From<num::ParseIntError> for ParameterScanError {20 fn from(e: num::ParseIntError) -> ParameterScanError {21 ParameterScanError::ParseIntError(e)22 }23}2425impl From<DecimalError> for ParameterScanError {26 fn from(e: DecimalError) -> ParameterScanError {27 ParameterScanError::ParseDecimalError(e)28 }29}3031impl fmt::Display for ParameterScanError {32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {33 match *self {34 ParameterScanError::ParseIntError(ref e) => write!(f, "{}", e),35 ParameterScanError::ParseDecimalError(ref e) => write!(f, "{}", e),36 ParameterScanError::EmptyRange => write!(f, "Empty parameter range"),37 ParameterScanError::TooLarge => write!(f, "Parameter range is too large"),38 ParameterScanError::ZeroStep => write!(f, "Zero is not a valid parameter step"),39 ParameterScanError::StepRequired => write!(40 f,41 "A step size is required when the range bounds are \42 floating point numbers. The step size can be specified \43 with the '--parameter-step-size' parameter"44 ),45 ParameterScanError::UnexpectedCommandNameCount(real, expected) => {46 write!(47 f,48 "'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",49 real, expected50 )51 }52 }53 }54}5556impl Error for ParameterScanError {}5758#[derive(Debug)]59pub enum OptionsError<'a> {60 RunsBelowTwo,61 EmptyRunsRange,62 TooManyCommandNames(usize),63 UnexpectedCommandNameCount(usize, usize),64 NumericParsingError(&'a str, ParseIntError),65}6667impl<'a> fmt::Display for OptionsError<'a> {68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {69 match *self {70 OptionsError::EmptyRunsRange => write!(f, "Empty runs range"),71 OptionsError::RunsBelowTwo => write!(f, "Number of runs below two"),72 OptionsError::TooManyCommandNames(n) => {73 write!(f, "Too many --command-name options: expected {} at most", n)74 }75 OptionsError::UnexpectedCommandNameCount(real, expected) => {76 write!(77 f,78 "'--command-name' has been specified {} times. It has to appear exactly once, or exactly {} times (number of benchmarks)",79 real, expected80 )81 }82 OptionsError::NumericParsingError(cmd, ref err) => write!(83 f,84 "Could not read numeric argument to '--{cmd}': {err}",85 cmd = cmd,86 err = err87 ),88 }89 }90}9192impl<'a> Error for OptionsError<'a> {}