File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ resolver = "2"
3
3
members = [
4
4
" valuable" ,
5
5
" valuable-derive" ,
6
+ " valuable-json" ,
6
7
" valuable-serde" ,
7
8
" tests" ,
8
9
]
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " valuable-json"
3
+ version = " 0.1.0"
4
+ authors = [
" Ning Sun <[email protected] >" ]
5
+ edition = " 2018"
6
+ license = " MIT"
7
+ description = " Valuable instrument for `serde_json::Value`"
8
+
9
+ [dependencies ]
10
+ valuable = { version = " 0.1" , path = " ../valuable" , default-features = false }
11
+ serde_json = " 1"
Original file line number Diff line number Diff line change
1
+ use serde_json:: { Value as JsonValue } ;
2
+ use valuable:: { Valuable , Value , Visit } ;
3
+
4
+ struct Json < ' a > ( & ' a JsonValue ) ;
5
+
6
+ impl < ' a > Valuable for Json < ' a > {
7
+ fn as_value ( & self ) -> Value < ' a > {
8
+ match self . 0 {
9
+ // TODO: fixme
10
+ JsonValue :: Array ( ref array) => Value :: Listable ( array) ,
11
+ JsonValue :: Bool ( ref value) => Value :: Bool ( * value) ,
12
+ JsonValue :: Number ( ref num) => {
13
+ // TODO: check correctness for this
14
+ if num. is_f64 ( ) {
15
+ Value :: F64 ( num. as_f64 ( ) . unwrap ( ) )
16
+ } else if num. is_i64 ( ) {
17
+ Value :: I64 ( num. as_i64 ( ) . unwrap ( ) )
18
+ } else if num. is_u64 ( ) {
19
+ Value :: U64 ( num. as_u64 ( ) . unwrap ( ) )
20
+ } else {
21
+ unreachable ! ( )
22
+ }
23
+ }
24
+ JsonValue :: Null => Value :: Unit ,
25
+ JsonValue :: String ( ref s) => Value :: String ( s) ,
26
+ JsonValue :: Object ( ref object) => {
27
+ // TODO: make map valuable
28
+ Value :: Mappable ( object) ,
29
+ }
30
+ }
31
+ }
32
+
33
+ fn visit ( & self , visit : & mut dyn Visit ) {
34
+ //TODO:
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments