graphrecords_query/error/
aggregation.rs1use crate::Diagnostic;
2use graphrecords_core::graphrecord::GraphRecordValue;
3use std::{
4 error::Error,
5 fmt::{self, Display, Formatter},
6};
7
8#[derive(Debug)]
9pub struct InvalidMedianValue {
10 value: GraphRecordValue,
11}
12
13impl InvalidMedianValue {
14 #[must_use]
15 pub const fn new(value: GraphRecordValue) -> Self {
16 Self { value }
17 }
18
19 #[must_use]
20 pub const fn value(&self) -> &GraphRecordValue {
21 &self.value
22 }
23}
24
25impl Display for InvalidMedianValue {
26 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
27 write!(
28 formatter,
29 "value `{}` cannot be included in a median calculation",
30 self.value
31 )
32 }
33}
34
35impl Error for InvalidMedianValue {}
36
37impl Diagnostic for InvalidMedianValue {
38 fn name() -> &'static str {
39 "InvalidMedianValue"
40 }
41
42 fn help(&self) -> Option<String> {
43 Some(
44 "narrow the values down first using is_int(), is_float(), is_datetime() or is_duration()"
45 .to_string(),
46 )
47 }
48}
49
50#[derive(Debug)]
51pub struct InvalidStandardDeviationValue {
52 value: GraphRecordValue,
53}
54
55impl InvalidStandardDeviationValue {
56 #[must_use]
57 pub const fn new(value: GraphRecordValue) -> Self {
58 Self { value }
59 }
60
61 #[must_use]
62 pub const fn value(&self) -> &GraphRecordValue {
63 &self.value
64 }
65}
66
67impl Display for InvalidStandardDeviationValue {
68 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
69 write!(
70 formatter,
71 "cannot calculate standard deviation of value `{}`",
72 self.value
73 )
74 }
75}
76
77impl Error for InvalidStandardDeviationValue {}
78
79impl Diagnostic for InvalidStandardDeviationValue {
80 fn name() -> &'static str {
81 "InvalidStandardDeviationValue"
82 }
83
84 fn help(&self) -> Option<String> {
85 Some("narrow the values down first using is_int() or is_float()".to_string())
86 }
87}
88
89#[derive(Debug)]
90pub struct InvalidVarianceValue {
91 value: GraphRecordValue,
92}
93
94impl InvalidVarianceValue {
95 #[must_use]
96 pub const fn new(value: GraphRecordValue) -> Self {
97 Self { value }
98 }
99
100 #[must_use]
101 pub const fn value(&self) -> &GraphRecordValue {
102 &self.value
103 }
104}
105
106impl Display for InvalidVarianceValue {
107 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
108 write!(
109 formatter,
110 "cannot calculate variance of value `{}`",
111 self.value
112 )
113 }
114}
115
116impl Error for InvalidVarianceValue {}
117
118impl Diagnostic for InvalidVarianceValue {
119 fn name() -> &'static str {
120 "InvalidVarianceValue"
121 }
122
123 fn help(&self) -> Option<String> {
124 Some("narrow the values down first using is_int() or is_float()".to_string())
125 }
126}