MCPcopy Create free account
hub / github.com/Keats/validator / display_errors

Function display_errors

validator/src/display_impl.rs:15–62  ·  view source on GitHub ↗
(
    fmt: &mut fmt::Formatter<'_>,
    errs: &ValidationErrorsKind,
    path: &str,
)

Source from the content-addressed store, hash-verified

13}
14
15fn 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
64impl fmt::Display for ValidationErrors {
65 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

Callers 2

display_structFunction · 0.85
fmtMethod · 0.85

Calls 1

display_structFunction · 0.85

Tested by

no test coverage detected