1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug)]
6pub enum StatsError {
7 BadParams,
9 ArgMustBePositive(&'static str),
11 ArgNotNegative(&'static str),
13 ArgIntervalIncl(&'static str, f64, f64),
15 ArgIntervalExcl(&'static str, f64, f64),
17 ArgIntervalExclMin(&'static str, f64, f64),
19 ArgIntervalExclMax(&'static str, f64, f64),
21 ArgGt(&'static str, f64),
23 ArgGtArg(&'static str, &'static str),
25 ArgGte(&'static str, f64),
27 ArgGteArg(&'static str, &'static str),
30 ArgLt(&'static str, f64),
32 ArgLtArg(&'static str, &'static str),
34 ArgLte(&'static str, f64),
36 ArgLteArg(&'static str, &'static str),
39 ContainersMustBeSameLength,
41 ComputationFailedToConverge,
43 ContainerExpectedSum(&'static str, f64),
45 ContainerExpectedSumVar(&'static str, &'static str),
47 SpecialCase(&'static str),
49}
50
51impl Error for StatsError {
52 fn description(&self) -> &str {
53 "Error performing statistical calculation"
54 }
55}
56
57impl fmt::Display for StatsError {
58 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59 match *self {
60 StatsError::BadParams => write!(f, "Bad distribution parameters"),
61 StatsError::ArgMustBePositive(s) => write!(f, "Argument {} must be positive", s),
62 StatsError::ArgNotNegative(s) => write!(f, "Argument {} must be non-negative", s),
63 StatsError::ArgIntervalIncl(s, min, max) => {
64 write!(f, "Argument {} not within interval [{}, {}]", s, min, max)
65 }
66 StatsError::ArgIntervalExcl(s, min, max) => {
67 write!(f, "Argument {} not within interval ({}, {})", s, min, max)
68 }
69 StatsError::ArgIntervalExclMin(s, min, max) => {
70 write!(f, "Argument {} not within interval ({}, {}]", s, min, max)
71 }
72 StatsError::ArgIntervalExclMax(s, min, max) => {
73 write!(f, "Argument {} not within interval [{}, {})", s, min, max)
74 }
75 StatsError::ArgGt(s, val) => write!(f, "Argument {} must be greater than {}", s, val),
76 StatsError::ArgGtArg(s, val) => {
77 write!(f, "Argument {} must be greater than {}", s, val)
78 }
79 StatsError::ArgGte(s, val) => {
80 write!(f, "Argument {} must be greater than or equal to {}", s, val)
81 }
82 StatsError::ArgGteArg(s, val) => {
83 write!(f, "Argument {} must be greater than or equal to {}", s, val)
84 }
85 StatsError::ArgLt(s, val) => write!(f, "Argument {} must be less than {}", s, val),
86 StatsError::ArgLtArg(s, val) => write!(f, "Argument {} must be less than {}", s, val),
87 StatsError::ArgLte(s, val) => {
88 write!(f, "Argument {} must be less than or equal to {}", s, val)
89 }
90 StatsError::ArgLteArg(s, val) => {
91 write!(f, "Argument {} must be less than or equal to {}", s, val)
92 }
93 StatsError::ContainersMustBeSameLength => {
94 write!(f, "Expected containers of same length")
95 }
96 StatsError::ComputationFailedToConverge => write!(f, "Computation failed to converge"),
97 StatsError::ContainerExpectedSum(s, sum) => {
98 write!(f, "Elements in container {} expected to sum to {}", s, sum)
99 }
100 StatsError::ContainerExpectedSumVar(s, sum) => {
101 write!(f, "Elements in container {} expected to sum to {}", s, sum)
102 }
103 StatsError::SpecialCase(s) => write!(f, "{}", s),
104 }
105 }
106}