Skip to content

Commit 67b5537

Browse files
committed
rustfmt
1 parent 9789ecc commit 67b5537

File tree

1 file changed

+78
-28
lines changed

1 file changed

+78
-28
lines changed

src/main.rs

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,24 @@ fn main() {
3939
Mismatch::NoMismatch => println!("No mismatch was found."),
4040
Mismatch::ValueMismatch => println!("Mismatch at root."),
4141
Mismatch::ObjectMismatch(None, None, None) => println!("No mismatch was found."),
42-
Mismatch::ObjectMismatch(a,b,c) => {
42+
Mismatch::ObjectMismatch(a, b, c) => {
4343
if let Some(left_keys) = a {
44-
println!("Following keys were not found in second object: {:?}", left_keys);
44+
println!(
45+
"Following keys were not found in second object: {:?}",
46+
left_keys
47+
);
4548
}
4649
if let Some(right_keys) = b {
47-
println!("Following keys were not found in first object: {:?}", right_keys);
50+
println!(
51+
"Following keys were not found in first object: {:?}",
52+
right_keys
53+
);
4854
}
4955
if let Some(unequal_keys) = c {
50-
println!("Following keys were not found to be equal: {:?}", unequal_keys);
56+
println!(
57+
"Following keys were not found to be equal: {:?}",
58+
unequal_keys
59+
);
5160
}
5261
}
5362
};
@@ -63,7 +72,11 @@ struct KeyMap {
6372
enum Mismatch {
6473
NoMismatch,
6574
ValueMismatch,
66-
ObjectMismatch(Option<BTreeSet<KeyMap>>, Option<BTreeSet<KeyMap>>, Option<BTreeSet<KeyMap>>),
75+
ObjectMismatch(
76+
Option<BTreeSet<KeyMap>>,
77+
Option<BTreeSet<KeyMap>>,
78+
Option<BTreeSet<KeyMap>>,
79+
),
6780
}
6881

6982
fn match_json(value: &Value, value1: &Value) -> Mismatch {
@@ -72,34 +85,62 @@ fn match_json(value: &Value, value1: &Value) -> Mismatch {
7285
let (left, right, intersection) = intersect_maps(&a, &b);
7386
let mut unequal_keys = None;
7487

75-
let mut left = left.map(|l| l.iter().map(|x| KeyMap{ key: String::from(x), children: None }).collect::<BTreeSet<KeyMap>>());
76-
let mut right = right.map(|r| r.iter().map(|x| KeyMap{ key: String::from(x), children: None }).collect::<BTreeSet<KeyMap>>());
88+
let mut left = left.map(|l| {
89+
l.iter()
90+
.map(|x| KeyMap {
91+
key: String::from(x),
92+
children: None,
93+
})
94+
.collect::<BTreeSet<KeyMap>>()
95+
});
96+
let mut right = right.map(|r| {
97+
r.iter()
98+
.map(|x| KeyMap {
99+
key: String::from(x),
100+
children: None,
101+
})
102+
.collect::<BTreeSet<KeyMap>>()
103+
});
77104

78105
if let Some(intersection) = intersection {
79106
for key in intersection {
80-
if let Some(keys) = match match_json(&a.get(&key).unwrap(), &b.get(&key).unwrap()) {
81-
Mismatch::NoMismatch => None,
82-
Mismatch::ValueMismatch => Some(KeyMap{ key, children: None }),
83-
Mismatch::ObjectMismatch(left_keys, right_keys, mismatch_keys) => {
84-
if let Some(left_keys) = left_keys {
85-
left.get_or_insert(BTreeSet::new()).insert(KeyMap{ key: String::from(&key), children: Some(left_keys) });
107+
if let Some(keys) =
108+
match match_json(&a.get(&key).unwrap(), &b.get(&key).unwrap()) {
109+
Mismatch::NoMismatch => None,
110+
Mismatch::ValueMismatch => Some(KeyMap {
111+
key,
112+
children: None,
113+
}),
114+
Mismatch::ObjectMismatch(left_keys, right_keys, mismatch_keys) => {
115+
if let Some(left_keys) = left_keys {
116+
left.get_or_insert(BTreeSet::new()).insert(KeyMap {
117+
key: String::from(&key),
118+
children: Some(left_keys),
119+
});
120+
}
121+
if let Some(right_keys) = right_keys {
122+
right.get_or_insert(BTreeSet::new()).insert(KeyMap {
123+
key: String::from(&key),
124+
children: Some(right_keys),
125+
});
126+
}
127+
if let Some(mismatch_keys) = mismatch_keys {
128+
Some(KeyMap {
129+
key: String::from(&key),
130+
children: Some(mismatch_keys),
131+
})
132+
} else {
133+
None
134+
}
86135
}
87-
if let Some(right_keys) = right_keys {
88-
right.get_or_insert(BTreeSet::new()).insert(KeyMap{ key: String::from(&key), children: Some(right_keys) });
89-
}
90-
if let Some(mismatch_keys) = mismatch_keys {
91-
Some(KeyMap{ key: String::from(&key), children: Some(mismatch_keys) })
92-
} else {
93-
None
94-
}
95-
},
96-
} {
136+
}
137+
{
97138
unequal_keys.get_or_insert(BTreeSet::new()).insert(keys);
98139
}
99140
}
100141
}
101142
Mismatch::ObjectMismatch(left, right, unequal_keys)
102-
},
143+
}
103144
(a, b) => {
104145
if a == b {
105146
Mismatch::NoMismatch
@@ -110,9 +151,14 @@ fn match_json(value: &Value, value1: &Value) -> Mismatch {
110151
}
111152
}
112153

113-
fn intersect_maps<'a>(a: &Map<String, Value>,
114-
b: &Map<String, Value>) -> (Option<BTreeSet<String>>,
115-
Option<BTreeSet<String>>, Option<BTreeSet<String>>) {
154+
fn intersect_maps(
155+
a: &Map<String, Value>,
156+
b: &Map<String, Value>,
157+
) -> (
158+
Option<BTreeSet<String>>,
159+
Option<BTreeSet<String>>,
160+
Option<BTreeSet<String>>,
161+
) {
116162
let mut intersection = BTreeSet::new();
117163
let mut left = BTreeSet::new();
118164
let mut right = BTreeSet::new();
@@ -130,6 +176,10 @@ fn intersect_maps<'a>(a: &Map<String, Value>,
130176
}
131177
let left = if left.len() == 0 { None } else { Some(left) };
132178
let right = if right.len() == 0 { None } else { Some(right) };
133-
let intersection = if intersection.len() == 0 { None } else { Some(intersection) };
179+
let intersection = if intersection.len() == 0 {
180+
None
181+
} else {
182+
Some(intersection)
183+
};
134184
(left, right, intersection)
135185
}

0 commit comments

Comments
 (0)