brunch/
error.rs

1/*!
2# Brunch
3*/
4
5use dactyl::NiceU32;
6use std::fmt;
7
8
9
10#[derive(Debug, Clone, Copy)]
11/// # Error.
12///
13/// This enum serves as the custom error type for `Brunch`.
14pub enum BrunchError {
15	/// # Duplicate name.
16	DupeName,
17
18	/// # No benches were specified.
19	NoBench,
20
21	/// # A bench was missing a [`Bench::run`](crate::Bench::run)-type call.
22	NoRun,
23
24	/// # General math failure. (Floats aren't fun.)
25	Overflow,
26
27	/// # The benchmark completed too quickly to analyze.
28	TooFast,
29
30	/// # Not enough samples were collected to analyze.
31	TooSmall(u32),
32
33	/// # The samples were too chaotic to analyze.
34	TooWild,
35}
36
37impl std::error::Error for BrunchError {}
38
39impl fmt::Display for BrunchError {
40	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41		match self {
42			Self::DupeName => f.write_str("Benchmark names must be unique."),
43			Self::NoBench => f.write_str("At least one benchmark is required."),
44			Self::NoRun => f.write_str("Missing \x1b[1;96mBench::run\x1b[0m."),
45			Self::Overflow => f.write_str("Unable to crunch the numbers."),
46			Self::TooFast => f.write_str("Too fast to benchmark!"),
47			Self::TooSmall(n) => write!(
48				f, "Insufficient samples collected ({}); try increasing the timeout.",
49				NiceU32::from(*n),
50			),
51			Self::TooWild => f.write_str("Samples too wild to analyze."),
52		}
53	}
54}