(
fmt: &mut fmt::Formatter<'_>,
errs: &ValidationErrorsKind,
path: &str,
)
| 13 | } |
| 14 | |
| 15 | fn display_errors( |
| 16 | fmt: &mut fmt::Formatter<'_>, |
| 17 | errs: &ValidationErrorsKind, |
| 18 | path: &str, |
| 19 | ) -> fmt::Result { |
| 20 | fn display_struct( |
| 21 | fmt: &mut fmt::Formatter<'_>, |
| 22 | errs: &ValidationErrors, |
| 23 | path: &str, |
| 24 | ) -> fmt::Result { |
| 25 | let mut full_path = String::new(); |
| 26 | write!(&mut full_path, "{}.", path)?; |
| 27 | let base_len = full_path.len(); |
| 28 | for (path, err) in errs.errors() { |
| 29 | write!(&mut full_path, "{}", path)?; |
| 30 | display_errors(fmt, err, &full_path)?; |
| 31 | full_path.truncate(base_len); |
| 32 | } |
| 33 | Ok(()) |
| 34 | } |
| 35 | |
| 36 | match errs { |
| 37 | ValidationErrorsKind::Field(errs) => { |
| 38 | write!(fmt, "{}: ", path)?; |
| 39 | let len = errs.len(); |
| 40 | for (idx, err) in errs.iter().enumerate() { |
| 41 | if idx + 1 == len { |
| 42 | write!(fmt, "{}", err)?; |
| 43 | } else { |
| 44 | write!(fmt, "{}, ", err)?; |
| 45 | } |
| 46 | } |
| 47 | Ok(()) |
| 48 | } |
| 49 | ValidationErrorsKind::Struct(errs) => display_struct(fmt, errs, path), |
| 50 | ValidationErrorsKind::List(errs) => { |
| 51 | let mut full_path = String::new(); |
| 52 | write!(&mut full_path, "{}", path)?; |
| 53 | let base_len = full_path.len(); |
| 54 | for (idx, err) in errs.iter() { |
| 55 | write!(&mut full_path, "[{}]", idx)?; |
| 56 | display_struct(fmt, err, &full_path)?; |
| 57 | full_path.truncate(base_len); |
| 58 | } |
| 59 | Ok(()) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | impl fmt::Display for ValidationErrors { |
| 65 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { |
no test coverage detected