@@ -4,14 +4,20 @@ extern crate serde;
44#[ macro_use]
55extern crate log;
66
7+ #[ cfg( test) ]
8+ #[ macro_use]
9+ extern crate serde_derive;
10+
711#[ macro_use]
812mod error;
913mod map;
1014mod seq;
1115mod var;
16+ mod serialize;
1217
1318pub use error:: Error ;
1419pub use xml:: reader:: { EventReader , ParserConfig } ;
20+ pub use serialize:: { serialize, Serializer } ;
1521
1622use error:: VResult ;
1723use xml:: reader:: XmlEvent ;
@@ -72,7 +78,7 @@ impl<'de, R: Read> Deserializer<R> {
7278 XmlEvent :: StartDocument { .. } |
7379 XmlEvent :: EndDocument { .. } |
7480 XmlEvent :: ProcessingInstruction { .. } |
75- XmlEvent :: Comment ( _) => { /* skip */ }
81+ XmlEvent :: Comment ( _) => { /* skip */ } ,
7682
7783 other => return Ok ( other) ,
7884 }
@@ -88,11 +94,11 @@ impl<'de, R: Read> Deserializer<R> {
8894 match next {
8995 XmlEvent :: StartElement { .. } => {
9096 self . depth += 1 ;
91- }
97+ } ,
9298 XmlEvent :: EndElement { .. } => {
9399 self . depth -= 1 ;
94- }
95- _ => { }
100+ } ,
101+ _ => { } ,
96102 }
97103 debug ! ( "Fetched {:?}" , next) ;
98104 Ok ( next)
@@ -106,10 +112,8 @@ impl<'de, R: Read> Deserializer<R> {
106112 :: std:: mem:: replace ( & mut self . is_map_value , false )
107113 }
108114
109- fn read_inner_value < V : Visitor < ' de > , F : FnOnce ( & mut Self ) -> VResult < V :: Value > > (
110- & mut self ,
111- f : F ,
112- ) -> VResult < V :: Value > {
115+ fn read_inner_value < V : Visitor < ' de > , F : FnOnce ( & mut Self ) -> VResult < V :: Value > > ( & mut self , f : F )
116+ -> VResult < V :: Value > {
113117 if self . unset_map_value ( ) {
114118 debug_expect ! ( self . next( ) , Ok ( XmlEvent :: StartElement { name, .. } ) => {
115119 let result = f( self ) ?;
@@ -162,12 +166,8 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer<R> {
162166 newtype_struct identifier
163167 }
164168
165- fn deserialize_struct < V : Visitor < ' de > > (
166- self ,
167- _name : & ' static str ,
168- fields : & ' static [ & ' static str ] ,
169- visitor : V ,
170- ) -> VResult < V :: Value > {
169+ fn deserialize_struct < V : Visitor < ' de > > ( self , _name : & ' static str , fields : & ' static [ & ' static str ] , visitor : V )
170+ -> VResult < V :: Value > {
171171 self . unset_map_value ( ) ;
172172 expect ! ( self . next( ) ?, XmlEvent :: StartElement { name, attributes, .. } => {
173173 let map_value = visitor. visit_map( MapAccess :: new(
@@ -248,33 +248,21 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer<R> {
248248 } )
249249 }
250250
251- fn deserialize_unit_struct < V : Visitor < ' de > > (
252- self ,
253- _name : & ' static str ,
254- visitor : V ,
255- ) -> VResult < V :: Value > {
251+ fn deserialize_unit_struct < V : Visitor < ' de > > ( self , _name : & ' static str , visitor : V ) -> VResult < V :: Value > {
256252 self . deserialize_unit ( visitor)
257253 }
258254
259- fn deserialize_tuple_struct < V : Visitor < ' de > > (
260- self ,
261- _name : & ' static str ,
262- len : usize ,
263- visitor : V ,
264- ) -> VResult < V :: Value > {
255+ fn deserialize_tuple_struct < V : Visitor < ' de > > ( self , _name : & ' static str , len : usize , visitor : V )
256+ -> VResult < V :: Value > {
265257 self . deserialize_tuple ( len, visitor)
266258 }
267259
268260 fn deserialize_tuple < V : Visitor < ' de > > ( self , len : usize , visitor : V ) -> VResult < V :: Value > {
269261 visitor. visit_seq ( SeqAccess :: new ( self , Some ( len) ) )
270262 }
271263
272- fn deserialize_enum < V : Visitor < ' de > > (
273- self ,
274- _name : & ' static str ,
275- _variants : & ' static [ & ' static str ] ,
276- visitor : V ,
277- ) -> VResult < V :: Value > {
264+ fn deserialize_enum < V : Visitor < ' de > > ( self , _name : & ' static str , _variants : & ' static [ & ' static str ] , visitor : V )
265+ -> VResult < V :: Value > {
278266 self . read_inner_value :: < V , _ > ( |this| visitor. visit_enum ( EnumAccess :: new ( this) ) )
279267 }
280268
0 commit comments