ferroui_base/data/
data_validation_exception.rs1use crate::data::core::ValueTypes;
2use crate::BoxedValue;
3use std::fmt;
4
5#[derive(Clone)]
8pub struct DataValidationException {
9 error_data: Option<BoxedValue>,
10 message: String,
11}
12
13impl DataValidationException {
14 pub fn new(error_data: Option<BoxedValue>) -> Self {
16 let message = match &error_data {
17 Some(v) => ValueTypes::to_display_string(Some(v)),
18 None => String::new(),
19 };
20 Self { error_data, message }
21 }
22
23 pub fn error_data(&self) -> Option<&BoxedValue> {
25 self.error_data.as_ref()
26 }
27}
28
29impl PartialEq for DataValidationException {
32 fn eq(&self, other: &Self) -> bool {
33 ValueTypes::identity_equals(self.error_data.as_ref(), other.error_data.as_ref())
34 }
35}
36
37impl fmt::Debug for DataValidationException {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 write!(f, "DataValidationException({})", self.message)
40 }
41}
42
43impl fmt::Display for DataValidationException {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 f.write_str(&self.message)
46 }
47}
48
49impl std::error::Error for DataValidationException {}
50
51#[derive(Clone, Debug)]
53pub struct AggregateException {
54 inner: Vec<DataValidationException>,
55}
56
57impl AggregateException {
58 pub fn new(inner: Vec<DataValidationException>) -> Self {
59 Self { inner }
60 }
61
62 pub fn inner_exceptions(&self) -> &[DataValidationException] {
63 &self.inner
64 }
65}
66
67impl fmt::Display for AggregateException {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 f.write_str("One or more errors occurred.")?;
70 for e in &self.inner {
71 write!(f, " ({e})")?;
72 }
73 Ok(())
74 }
75}
76
77impl std::error::Error for AggregateException {}