xcsp3_rust/errors/
xcsp3error.rs1pub mod xcsp3_core {
42 use crate::errors::parse_constraint_error::xcsp3_core::ParseConstraintError;
43 use crate::errors::parse_domain_error::xcsp3_core::ParseDomainError;
44 use crate::errors::parse_objectives_error::xcsp3_core::ParseObjectivesError;
45 use crate::errors::parse_variable_error::ParseVariableError;
46 use quick_xml::DeError;
47 use std::fmt::{Display, Formatter};
48
49 #[derive(Debug, Clone)]
50 pub enum Xcsp3Error {
51 ParseDomainError(ParseDomainError),
52 ParseVariableError(ParseVariableError),
53 ParseConstraintError(ParseConstraintError),
54 ParseObjectivesError(ParseObjectivesError),
55 ReadXmlError(DeError),
56 }
57
58 impl Display for Xcsp3Error {
59 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
60 write!(
61 f,
62 "{}",
63 match self {
64 Xcsp3Error::ParseDomainError(e) => e.to_string(),
65 Xcsp3Error::ParseVariableError(e) => e.to_string(),
66 Xcsp3Error::ParseConstraintError(e) => e.to_string(),
67 Xcsp3Error::ParseObjectivesError(e) => e.to_string(),
68 Xcsp3Error::ReadXmlError(e) => e.to_string(),
69 }
70 )
71 }
72 }
73
74 impl Xcsp3Error {
76 pub fn get_read_xml_error(err: DeError) -> Xcsp3Error {
77 Xcsp3Error::ReadXmlError(err)
78 }
79 pub fn get_constraint_slide_error(s: &str) -> Xcsp3Error {
80 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_slide_error(s))
81 }
82 pub fn get_objective_scope_error(s: &str) -> Xcsp3Error {
83 Xcsp3Error::ParseObjectivesError(ParseObjectivesError::get_scope_error(s))
84 }
85
86 pub fn get_objective_coeffs_error(s: &str) -> Xcsp3Error {
87 Xcsp3Error::ParseObjectivesError(ParseObjectivesError::get_coeffs_error(s))
88 }
89
90 pub fn get_objective_type_error(s: &str) -> Xcsp3Error {
91 Xcsp3Error::ParseObjectivesError(ParseObjectivesError::get_type_error(s))
92 }
93
94 pub fn get_objective_target_error(s: &str) -> Xcsp3Error {
95 Xcsp3Error::ParseObjectivesError(ParseObjectivesError::get_target_error(s))
96 }
97
98 pub fn get_constraint_element_error(s: &str) -> Xcsp3Error {
99 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_element_error(s))
100 }
101 pub fn get_constraint_count_error(s: &str) -> Xcsp3Error {
102 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_count_error(s))
103 }
104
105 pub fn get_constraint_no_overlap_error(s: &str) -> Xcsp3Error {
106 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_no_overlap_error(s))
107 }
108
109 pub fn get_constraint_cumulative_error(s: &str) -> Xcsp3Error {
110 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_cumulative_error(s))
111 }
112
113 pub fn get_constraint_cardinality_error(s: &str) -> Xcsp3Error {
114 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_cardinality_error(s))
115 }
116 pub fn get_constraint_sum_error(s: &str) -> Xcsp3Error {
117 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_sum_error(s))
118 }
119 pub fn get_constraint_group_error(s: &str) -> Xcsp3Error {
120 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_group_error(s))
121 }
122 pub fn get_constraint_expression_error(s: &str) -> Xcsp3Error {
123 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_expression_error(s))
124 }
125
126 pub fn get_constraint_channel_error(s: &str) -> Xcsp3Error {
127 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_channel_error(s))
128 }
129 pub fn get_constraint_extension_error(s: &str) -> Xcsp3Error {
130 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_extension_error(s))
131 }
132
133 pub fn get_constraint_scope_not_found_error(s: &str) -> Xcsp3Error {
134 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_scope_not_found_error(s))
135 }
136
137 pub fn get_constraint_regular_transitions_error(s: &str) -> Xcsp3Error {
138 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_regular_transitions_error(s))
139 }
140
141 pub fn get_constraint_list_of_values_error(s: &str) -> Xcsp3Error {
142 Xcsp3Error::ParseConstraintError(ParseConstraintError::get_list_of_values_error(s))
143 }
144 pub fn get_domain_integer_error(s: &str) -> Xcsp3Error {
145 Xcsp3Error::ParseDomainError(ParseDomainError::get_integer_error(s))
146 }
147
148 pub fn get_domain_interval_error(s: &str) -> Xcsp3Error {
149 Xcsp3Error::ParseDomainError(ParseDomainError::get_interval_error(s))
150 }
151
152 pub fn get_domain_for_error(s: &str) -> Xcsp3Error {
153 Xcsp3Error::ParseDomainError(ParseDomainError::get_domain_for_error(s))
154 }
155
156 pub fn get_variable_not_found_error(s: &str) -> Xcsp3Error {
157 Xcsp3Error::ParseVariableError(ParseVariableError::get_not_found_error(s))
158 }
159
160 pub fn get_variable_size_invalid_error(s: &str) -> Xcsp3Error {
161 Xcsp3Error::ParseVariableError(ParseVariableError::get_size_invalid_error(s))
162 }
163 }
164}