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