@@ -5,7 +5,7 @@ use itertools::Itertools as _;
55use serde:: { Deserialize , Serialize } ;
66use serde_json:: Value ;
77
8- /// Prerenedered json.
8+ /// Prerendered json.
99///
1010/// Both the Display and serde_json::to_string implementations write the serialized json
1111#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Serialize , Deserialize ) ]
@@ -16,25 +16,21 @@ pub(crate) struct OrderedJson(String);
1616impl OrderedJson {
1717 /// If you pass in an array, it will not be sorted.
1818 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) ?) )
2020 }
2121
2222 /// 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 {
2624 let items = items
2725 . into_iter ( )
2826 . sorted_unstable_by ( |a, b| a. borrow ( ) . cmp ( & b. borrow ( ) ) )
2927 . format_with ( "," , |item, f| f ( item. borrow ( ) ) ) ;
30- OrderedJson ( format ! ( "[{}]" , items) )
28+ Self ( format ! ( "[{}]" , items) )
3129 }
3230
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 {
3632 let items = items. into_iter ( ) . format_with ( "," , |item, f| f ( item. borrow ( ) ) ) ;
37- OrderedJson ( format ! ( "[{items}]" ) )
33+ Self ( format ! ( "[{items}]" ) )
3834 }
3935}
4036
@@ -48,7 +44,7 @@ impl From<Value> for OrderedJson {
4844 fn from ( value : Value ) -> Self {
4945 let serialized =
5046 serde_json:: to_string ( & value) . expect ( "Serializing a Value to String should never fail" ) ;
51- OrderedJson ( serialized)
47+ Self ( serialized)
5248 }
5349}
5450
@@ -69,7 +65,7 @@ pub(crate) struct EscapedJson(OrderedJson);
6965
7066impl From < OrderedJson > for EscapedJson {
7167 fn from ( json : OrderedJson ) -> Self {
72- EscapedJson ( json)
68+ Self ( json)
7369 }
7470}
7571
0 commit comments