@@ -43,11 +43,7 @@ impl JsonDiff {
43
43
/// returns it as a formatted string.
44
44
pub fn diff_string ( json1 : & Value , json2 : & Value , keys_only : bool ) -> Option < String > {
45
45
let Self { score : _, diff } = Self :: diff ( json1, json2, keys_only) ;
46
- if let Some ( value) = diff {
47
- Some ( colorize_to_array ( & value) . join ( "\n " ) + "\n " )
48
- } else {
49
- None
50
- }
46
+ diff. map ( |value| colorize_to_array ( & value) . join ( "\n " ) + "\n " )
51
47
}
52
48
53
49
fn object_diff ( obj1 : & Map < String , Value > , obj2 : & Map < String , Value > , keys_only : bool ) -> Self {
@@ -76,11 +72,11 @@ impl JsonDiff {
76
72
let Self {
77
73
score : subscore,
78
74
diff : change,
79
- } = Self :: diff_with_score ( & value1, & value2, keys_only) ;
75
+ } = Self :: diff_with_score ( value1, value2, keys_only) ;
80
76
if let Some ( change) = change {
81
77
result. insert ( key. clone ( ) , change) ;
82
78
}
83
- score += ( ( subscore / 5. ) . max ( -10. ) ) . min ( 20. ) ;
79
+ score += ( subscore / 5. ) . clamp ( -10. , 20. ) ;
84
80
}
85
81
}
86
82
@@ -117,7 +113,7 @@ impl JsonDiff {
117
113
118
114
for ( match_index, ( key, candidate) ) in fuzzy_originals. into_iter ( ) . enumerate ( ) {
119
115
if key != "__next" {
120
- let index_distance = ( match_index as isize - index as isize ) . abs ( ) as usize ;
116
+ let index_distance = ( match_index as isize - index as isize ) . unsigned_abs ( ) ;
121
117
if Self :: check_type ( item, candidate) {
122
118
let Self { score, diff : _ } = Self :: diff ( item, candidate, false ) ;
123
119
if best_match. as_ref ( ) . map_or ( true , |v| score > v. score )
0 commit comments