1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use serde_derive::Serialize; use std::fmt; #[derive(Debug, Serialize)] pub struct ValidationError { keyword: String, #[serde(rename = "schemaPath")] schema_path: String, #[serde(rename = "dataPath")] data_path: String, message: String, } impl ValidationError { pub fn keyword(&self) -> &str { &self.keyword } pub fn schema_path(&self) -> &str { &self.schema_path } pub fn data_path(&self) -> &str { &self.data_path } pub fn message(&self) -> &str { &self.message } } impl ValidationError { pub fn new<S1, S2, S3, S4>(keyword: S1, schema_path: S2, data_path: S3, message: S4) -> ValidationError where S1: Into<String>, S2: Into<String>, S3: Into<String>, S4: Into<String>, { ValidationError { keyword: keyword.into(), schema_path: schema_path.into(), data_path: data_path.into(), message: message.into(), } } } impl fmt::Display for ValidationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "schema path: '{}', data path: '{}', keyword: '{}', message: '{}'", self.schema_path, self.data_path, self.keyword, self.message ) } } impl std::error::Error for ValidationError {}