/src/serde-yaml/src/value/debug.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::mapping::Mapping; |
2 | | use crate::value::{Number, Value}; |
3 | | use std::fmt::{self, Debug, Display}; |
4 | | |
5 | | impl Debug for Value { |
6 | 0 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
7 | 0 | match self { |
8 | 0 | Value::Null => formatter.write_str("Null"), |
9 | 0 | Value::Bool(boolean) => write!(formatter, "Bool({})", boolean), |
10 | 0 | Value::Number(number) => write!(formatter, "Number({})", number), |
11 | 0 | Value::String(string) => write!(formatter, "String({:?})", string), |
12 | 0 | Value::Sequence(sequence) => { |
13 | 0 | formatter.write_str("Sequence ")?; |
14 | 0 | formatter.debug_list().entries(sequence).finish() |
15 | | } |
16 | 0 | Value::Mapping(mapping) => Debug::fmt(mapping, formatter), |
17 | 0 | Value::Tagged(tagged) => Debug::fmt(tagged, formatter), |
18 | | } |
19 | 0 | } |
20 | | } |
21 | | |
22 | | struct DisplayNumber<'a>(&'a Number); |
23 | | |
24 | | impl<'a> Debug for DisplayNumber<'a> { |
25 | 0 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
26 | 0 | Display::fmt(self.0, formatter) |
27 | 0 | } |
28 | | } |
29 | | |
30 | | impl Debug for Number { |
31 | 0 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
32 | 0 | write!(formatter, "Number({})", self) |
33 | 0 | } |
34 | | } |
35 | | |
36 | | impl Debug for Mapping { |
37 | 0 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
38 | 0 | formatter.write_str("Mapping ")?; |
39 | 0 | let mut debug = formatter.debug_map(); |
40 | 0 | for (k, v) in self { |
41 | | let tmp; |
42 | 0 | debug.entry( |
43 | 0 | match k { |
44 | 0 | Value::Bool(boolean) => boolean, |
45 | 0 | Value::Number(number) => { |
46 | 0 | tmp = DisplayNumber(number); |
47 | 0 | &tmp |
48 | | } |
49 | 0 | Value::String(string) => string, |
50 | 0 | _ => k, |
51 | | }, |
52 | 0 | v, |
53 | | ); |
54 | | } |
55 | 0 | debug.finish() |
56 | 0 | } |
57 | | } |