@@ -5,7 +5,7 @@ use itertools::Itertools as _;
5
5
use serde:: { Deserialize , Serialize } ;
6
6
use serde_json:: Value ;
7
7
8
- /// Prerenedered json.
8
+ /// Prerendered json.
9
9
///
10
10
/// Both the Display and serde_json::to_string implementations write the serialized json
11
11
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Serialize , Deserialize ) ]
@@ -16,25 +16,21 @@ pub(crate) struct OrderedJson(String);
16
16
impl OrderedJson {
17
17
/// If you pass in an array, it will not be sorted.
18
18
pub ( crate ) fn serialize < T : Serialize > ( item : T ) -> Result < Self , serde_json:: Error > {
19
- Ok ( OrderedJson ( serde_json:: to_string ( & item) ?) )
19
+ Ok ( Self ( serde_json:: to_string ( & item) ?) )
20
20
}
21
21
22
22
/// Serializes and sorts
23
- pub ( crate ) fn array_sorted < T : Borrow < OrderedJson > , I : IntoIterator < Item = T > > (
24
- items : I ,
25
- ) -> Self {
23
+ pub ( crate ) fn array_sorted < T : Borrow < Self > , I : IntoIterator < Item = T > > ( items : I ) -> Self {
26
24
let items = items
27
25
. into_iter ( )
28
26
. sorted_unstable_by ( |a, b| a. borrow ( ) . cmp ( & b. borrow ( ) ) )
29
27
. format_with ( "," , |item, f| f ( item. borrow ( ) ) ) ;
30
- OrderedJson ( format ! ( "[{}]" , items) )
28
+ Self ( format ! ( "[{}]" , items) )
31
29
}
32
30
33
- pub ( crate ) fn array_unsorted < T : Borrow < OrderedJson > , I : IntoIterator < Item = T > > (
34
- items : I ,
35
- ) -> Self {
31
+ pub ( crate ) fn array_unsorted < T : Borrow < Self > , I : IntoIterator < Item = T > > ( items : I ) -> Self {
36
32
let items = items. into_iter ( ) . format_with ( "," , |item, f| f ( item. borrow ( ) ) ) ;
37
- OrderedJson ( format ! ( "[{items}]" ) )
33
+ Self ( format ! ( "[{items}]" ) )
38
34
}
39
35
}
40
36
@@ -48,7 +44,7 @@ impl From<Value> for OrderedJson {
48
44
fn from ( value : Value ) -> Self {
49
45
let serialized =
50
46
serde_json:: to_string ( & value) . expect ( "Serializing a Value to String should never fail" ) ;
51
- OrderedJson ( serialized)
47
+ Self ( serialized)
52
48
}
53
49
}
54
50
@@ -69,7 +65,7 @@ pub(crate) struct EscapedJson(OrderedJson);
69
65
70
66
impl From < OrderedJson > for EscapedJson {
71
67
fn from ( json : OrderedJson ) -> Self {
72
- EscapedJson ( json)
68
+ Self ( json)
73
69
}
74
70
}
75
71
0 commit comments