ndarray_histogram/histogram/
errors.rs1use crate::errors::{EmptyInput, MinMaxError};
4use std::error;
5use std::fmt;
6
7#[derive(Debug, Clone)]
9pub struct BinNotFound;
10
11impl fmt::Display for BinNotFound {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 write!(f, "No bin has been found.")
14 }
15}
16
17impl error::Error for BinNotFound {
18 fn description(&self) -> &str {
19 "No bin has been found."
20 }
21}
22
23#[derive(Debug, Clone)]
25pub enum BinsBuildError {
26 EmptyInput,
28 Strategy,
30 #[doc(hidden)]
31 __NonExhaustive,
32}
33
34impl BinsBuildError {
35 pub fn is_empty_input(&self) -> bool {
37 matches!(self, BinsBuildError::EmptyInput)
38 }
39
40 pub fn is_strategy(&self) -> bool {
42 matches!(self, BinsBuildError::Strategy)
43 }
44}
45
46impl fmt::Display for BinsBuildError {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 write!(f, "The strategy failed to determine a non-zero bin width.")
49 }
50}
51
52impl error::Error for BinsBuildError {
53 fn description(&self) -> &str {
54 "The strategy failed to determine a non-zero bin width."
55 }
56}
57
58impl From<EmptyInput> for BinsBuildError {
59 fn from(_: EmptyInput) -> Self {
60 BinsBuildError::EmptyInput
61 }
62}
63
64impl From<MinMaxError> for BinsBuildError {
65 fn from(err: MinMaxError) -> BinsBuildError {
66 match err {
67 MinMaxError::EmptyInput => BinsBuildError::EmptyInput,
68 MinMaxError::UndefinedOrder => BinsBuildError::Strategy,
69 }
70 }
71}