hdrhistogram/errors/
mod.rs1use std::error::Error;
3use std::fmt;
4
5#[derive(Debug, Eq, PartialEq, Clone, Copy)]
7pub enum CreationError {
8 LowIsZero,
10 LowExceedsMax,
13 HighLessThanTwiceLow,
16 SigFigExceedsMax,
20 CannotRepresentSigFigBeyondLow,
28 UsizeTypeTooSmall,
31}
32
33#[derive(Debug, Eq, PartialEq, Clone, Copy)]
36pub enum AdditionError {
37 OtherAddendValueExceedsRange,
40 ResizeFailedUsizeTypeTooSmall,
44}
45
46#[derive(Debug, Eq, PartialEq, Clone, Copy)]
48pub enum SubtractionError {
49 SubtrahendValueExceedsMinuendRange,
52 SubtrahendCountExceedsMinuendCount,
56}
57
58#[derive(Debug, Eq, PartialEq, Clone, Copy)]
62pub enum RecordError {
63 ValueOutOfRangeResizeDisabled,
67 ResizeFailedUsizeTypeTooSmall,
71}
72
73#[allow(missing_docs)]
74#[derive(Debug)]
75pub struct UsizeTypeTooSmall;
76
77impl fmt::Display for CreationError {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79 match self {
80 CreationError::LowIsZero => write!(f, "Lowest discernible value must be >= 1"),
81 CreationError::LowExceedsMax => write!(f, "Lowest discernible value must be <= `u64::max_value() / 2`"),
82 CreationError::HighLessThanTwiceLow => write!(f, "Highest trackable value must be >= 2 * lowest discernible value for some internal calculations"),
83 CreationError::SigFigExceedsMax => write!(f, "Number of significant digits must be in the range `[0, 5]`"),
84 CreationError::CannotRepresentSigFigBeyondLow => write!(f, "Cannot represent sigfig worth of values beyond the lowest discernible value"),
85 CreationError::UsizeTypeTooSmall => write!(f, "The `usize` type is too small to represent the desired configuration"),
86 }
87 }
88}
89
90impl Error for CreationError {}
91
92impl fmt::Display for AdditionError {
93 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
94 match self {
95 AdditionError::OtherAddendValueExceedsRange => write!(f, "The other histogram includes values that do not fit in this histogram's range"),
96 AdditionError::ResizeFailedUsizeTypeTooSmall => write!(f, "The other histogram includes values that would map to indexes in this histogram that are not expressible for `usize`"),
97 }
98 }
99}
100
101impl Error for AdditionError {}
102
103impl fmt::Display for SubtractionError {
104 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105 match self {
106 SubtractionError::SubtrahendValueExceedsMinuendRange => write!(f, "The other histogram includes values that do not fit in this histogram's range"),
107 SubtractionError::SubtrahendCountExceedsMinuendCount => write!(f, "The other histogram includes counts that are higher than the current count for a value, and counts cannot go negative"),
108 }
109 }
110}
111
112impl Error for SubtractionError {}
113
114impl fmt::Display for RecordError {
115 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
116 match self {
117 RecordError::ValueOutOfRangeResizeDisabled => write!(f, "The value to record is not representable in this histogram and resizing is disabled"),
118 RecordError::ResizeFailedUsizeTypeTooSmall => write!(f, "Auto resizing is enabled and must be used to represent the provided value, but the histogram cannot be resized because `usize` cannot represent sufficient length"),
119 }
120 }
121}
122
123impl Error for RecordError {}
124
125impl fmt::Display for UsizeTypeTooSmall {
126 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127 write!(
128 f,
129 "The `usize` type is too small to represent the desired configuration"
130 )
131 }
132}
133
134impl Error for UsizeTypeTooSmall {}