use dactyl::NiceU32;
use std::fmt;
#[derive(Debug, Clone, Copy)]
pub enum BrunchError {
DupeName,
NoBench,
NoRun,
Overflow,
TooFast,
TooSmall(u32),
TooWild,
}
impl std::error::Error for BrunchError {}
impl fmt::Display for BrunchError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DupeName => f.write_str("Benchmark names must be unique."),
Self::NoBench => f.write_str("At least one benchmark is required."),
Self::NoRun => f.write_str("Missing \x1b[1;96mBench::run\x1b[0m."),
Self::Overflow => f.write_str("Unable to crunch the numbers."),
Self::TooFast => f.write_str("Too fast to benchmark!"),
Self::TooSmall(n) => write!(
f, "Insufficient samples collected ({}); try increasing the timeout.",
NiceU32::from(*n),
),
Self::TooWild => f.write_str("Samples too wild to analyze."),
}
}
}