pactum_annotations/
error.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct FieldIssue {
9 pub field: String,
11 pub code: String,
13 pub reason: String,
15}
16
17impl FieldIssue {
18 pub fn new(
19 field: impl Into<String>,
20 code: impl Into<String>,
21 reason: impl Into<String>,
22 ) -> Self {
23 Self {
24 field: field.into(),
25 code: code.into(),
26 reason: reason.into(),
27 }
28 }
29}
30
31impl std::fmt::Display for FieldIssue {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 write!(f, "{}: {} ({})", self.field, self.reason, self.code)
34 }
35}
36
37impl std::error::Error for FieldIssue {}
38
39impl crate::traits::Normalize for FieldIssue {
40 fn normalize(&mut self) {}
41}
42
43impl crate::traits::Validate for FieldIssue {
44 fn validate_with(&self, _ctx: &crate::context::ValidationContext) -> Result<(), Vec<FieldIssue>> {
45 Ok(())
46 }
47}