File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ use anyhow:: Result ;
2+ use olpc_cjson:: CanonicalFormatter ;
3+ use std:: io;
4+
5+ pub ( crate ) trait JsonOrderedSerialize {
6+ fn to_json_canonical_string ( & self ) -> Result < String > ;
7+ fn to_json_canonical_writer < W > ( & self , writer : W ) -> Result < ( ) >
8+ where
9+ W : io:: Write ;
10+ }
11+
12+ impl < S > JsonOrderedSerialize for S
13+ where
14+ S : serde:: ser:: Serialize ,
15+ {
16+ fn to_json_canonical_string ( & self ) -> Result < String > {
17+ let mut ser = serde_json:: Serializer :: with_formatter ( Vec :: new ( ) , CanonicalFormatter :: new ( ) ) ;
18+ self . serialize ( & mut ser) ?;
19+ let str = String :: from_utf8 ( ser. into_inner ( ) ) ?;
20+ Ok ( str)
21+ }
22+
23+ fn to_json_canonical_writer < W > ( & self , writer : W ) -> Result < ( ) >
24+ where
25+ W : io:: Write ,
26+ {
27+ let mut ser = serde_json:: Serializer :: with_formatter ( writer, CanonicalFormatter :: new ( ) ) ;
28+ self . serialize ( & mut ser) ?;
29+ ser. into_inner ( ) . flush ( ) ?;
30+ Ok ( ( ) )
31+ }
32+ }
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ pub(crate) mod ostree_manual;
6161
6262pub ( crate ) mod statistics;
6363
64+ mod json;
6465mod utils;
6566
6667#[ cfg( feature = "docgen" ) ]
You can’t perform that action at this time.
0 commit comments