@@ -10,39 +10,6 @@ use object::Object;
1010
1111use { JsonValue , Null } ;
1212
13- macro_rules! implement_extras {
14- ( $from: ty) => {
15- impl From <Option <$from>> for JsonValue {
16- fn from( val: Option <$from>) -> JsonValue {
17- match val {
18- Some ( value) => value. into( ) ,
19- None => Null ,
20- }
21- }
22- }
23-
24- impl From <Vec <$from>> for JsonValue {
25- fn from( mut val: Vec <$from>) -> JsonValue {
26- JsonValue :: Array (
27- val. drain( ..)
28- . map( |value| value. into( ) )
29- . collect( )
30- )
31- }
32- }
33-
34- impl From <Vec <Option <$from>>> for JsonValue {
35- fn from( mut val: Vec <Option <$from>>) -> JsonValue {
36- JsonValue :: Array (
37- val. drain( ..)
38- . map( |item| item. into( ) )
39- . collect( )
40- )
41- }
42- }
43- }
44- }
45-
4613macro_rules! implement_eq {
4714 ( $to: ident, $from: ty) => {
4815 impl PartialEq <$from> for JsonValue {
@@ -83,7 +50,6 @@ macro_rules! implement {
8350 }
8451
8552 implement_eq!( $to, $from) ;
86- implement_extras!( $from) ;
8753 } ;
8854 ( $to: ident, $from: ty) => {
8955 impl From <$from> for JsonValue {
@@ -93,7 +59,6 @@ macro_rules! implement {
9359 }
9460
9561 implement_eq!( $to, $from) ;
96- implement_extras!( $from) ;
9762 }
9863}
9964
@@ -107,15 +72,27 @@ impl<'a> From<&'a str> for JsonValue {
10772 }
10873}
10974
110- impl < ' a > From < Option < & ' a str > > for JsonValue {
111- fn from ( val : Option < & ' a str > ) -> JsonValue {
75+ impl < T : Into < JsonValue > > From < Option < T > > for JsonValue {
76+ fn from ( val : Option < T > ) -> JsonValue {
11277 match val {
113- Some ( value ) => value . into ( ) ,
114- None => Null ,
78+ Some ( val ) => val . into ( ) ,
79+ None => JsonValue :: Null ,
11580 }
11681 }
11782}
11883
84+ impl < T : Into < JsonValue > > From < Vec < T > > for JsonValue {
85+ fn from ( val : Vec < T > ) -> JsonValue {
86+ let mut array = Vec :: with_capacity ( val. len ( ) ) ;
87+
88+ for val in val {
89+ array. push ( val. into ( ) ) ;
90+ }
91+
92+ JsonValue :: Array ( array)
93+ }
94+ }
95+
11996impl From < HashMap < String , JsonValue > > for JsonValue {
12097 fn from ( mut val : HashMap < String , JsonValue > ) -> JsonValue {
12198 let mut object = Object :: with_capacity ( val. len ( ) ) ;
@@ -128,15 +105,6 @@ impl From<HashMap<String, JsonValue>> for JsonValue {
128105 }
129106}
130107
131- impl From < Option < HashMap < String , JsonValue > > > for JsonValue {
132- fn from ( val : Option < HashMap < String , JsonValue > > ) -> JsonValue {
133- match val {
134- Some ( value) => value. into ( ) ,
135- None => Null ,
136- }
137- }
138- }
139-
140108impl From < BTreeMap < String , JsonValue > > for JsonValue {
141109 fn from ( mut val : BTreeMap < String , JsonValue > ) -> JsonValue {
142110 let mut object = Object :: with_capacity ( val. len ( ) ) ;
@@ -153,24 +121,6 @@ impl From<BTreeMap<String, JsonValue>> for JsonValue {
153121 }
154122}
155123
156- impl From < Option < BTreeMap < String , JsonValue > > > for JsonValue {
157- fn from ( val : Option < BTreeMap < String , JsonValue > > ) -> JsonValue {
158- match val {
159- Some ( value) => value. into ( ) ,
160- None => Null ,
161- }
162- }
163- }
164-
165- impl From < Option < JsonValue > > for JsonValue {
166- fn from ( val : Option < JsonValue > ) -> JsonValue {
167- match val {
168- Some ( value) => value,
169- None => Null ,
170- }
171- }
172- }
173-
174124impl < ' a > PartialEq < & ' a str > for JsonValue {
175125 fn eq ( & self , other : & & str ) -> bool {
176126 match * self {
@@ -226,5 +176,4 @@ implement!(Number, f32 as num);
226176implement ! ( Number , f64 as num) ;
227177implement ! ( Number , Number ) ;
228178implement ! ( Object , Object ) ;
229- implement ! ( Array , Vec <JsonValue >) ;
230179implement ! ( Boolean , bool ) ;
0 commit comments