@@ -187,6 +187,80 @@ impl de::Error for Error {
187
187
}
188
188
}
189
189
190
+ pub struct BsonVisitor ;
191
+
192
+ impl de:: Visitor for BsonVisitor {
193
+ type Value = Bson ;
194
+
195
+ #[ inline]
196
+ fn visit_bool < E > ( & mut self , value : bool ) -> Result < Bson , E > {
197
+ Ok ( Bson :: Boolean ( value) )
198
+ }
199
+
200
+ #[ inline]
201
+ fn visit_i64 < E > ( & mut self , value : i64 ) -> Result < Bson , E > {
202
+ Ok ( Bson :: I64 ( value) )
203
+ }
204
+
205
+ #[ inline]
206
+ fn visit_u64 < E > ( & mut self , value : u64 ) -> Result < Bson , E > {
207
+ Ok ( Bson :: FloatingPoint ( value as f64 ) )
208
+ }
209
+
210
+ #[ inline]
211
+ fn visit_f64 < E > ( & mut self , value : f64 ) -> Result < Bson , E > {
212
+ Ok ( Bson :: FloatingPoint ( value) )
213
+ }
214
+
215
+ #[ inline]
216
+ fn visit_str < E > ( & mut self , value : & str ) -> Result < Bson , E >
217
+ where E : de:: Error ,
218
+ {
219
+ self . visit_string ( String :: from ( value) )
220
+ }
221
+
222
+ #[ inline]
223
+ fn visit_string < E > ( & mut self , value : String ) -> Result < Bson , E > {
224
+ Ok ( Bson :: String ( value) )
225
+ }
226
+
227
+ #[ inline]
228
+ fn visit_none < E > ( & mut self ) -> Result < Bson , E > {
229
+ Ok ( Bson :: Null )
230
+ }
231
+
232
+ #[ inline]
233
+ fn visit_some < D > ( & mut self , deserializer : & mut D ) -> Result < Bson , D :: Error >
234
+ where D : de:: Deserializer ,
235
+ {
236
+ de:: Deserialize :: deserialize ( deserializer)
237
+ }
238
+
239
+ #[ inline]
240
+ fn visit_unit < E > ( & mut self ) -> Result < Bson , E > {
241
+ Ok ( Bson :: Null )
242
+ }
243
+
244
+ #[ inline]
245
+ fn visit_seq < V > ( & mut self , visitor : V ) -> Result < Bson , V :: Error >
246
+ where V : de:: SeqVisitor ,
247
+ {
248
+ let values = try!( de:: impls:: VecVisitor :: new ( ) . visit_seq ( visitor) ) ;
249
+ Ok ( Bson :: Array ( values) )
250
+ }
251
+
252
+ #[ inline]
253
+ fn visit_map < V > ( & mut self , visitor : V ) -> Result < Bson , V :: Error >
254
+ where V : de:: MapVisitor ,
255
+ {
256
+ let values = try!( de:: impls:: BTreeMapVisitor :: new ( ) . visit_map ( visitor) ) ;
257
+ let values2 = values. clone ( ) ;
258
+ println ! ( "{:?}" , Bson :: from_extended_document( values2. into( ) ) ) ;
259
+ Ok ( Bson :: from_extended_document ( values. into ( ) ) . unwrap ( ) )
260
+ }
261
+ }
262
+
263
+
190
264
#[ derive( Debug ) ]
191
265
enum State {
192
266
Bson ( Bson ) ,
@@ -382,7 +456,9 @@ impl ser::Serializer for Serializer {
382
456
state => panic ! ( "expected object, found {:?}" , state) ,
383
457
} ;
384
458
459
+ println ! ( "VALUES FROM VISIT_MAP: {:?} // {:?}" , & values, values. get( "$oid" ) ) ;
385
460
let bson = Bson :: from_extended_document ( values) . unwrap ( ) ;
461
+
386
462
self . state . push ( State :: Bson ( bson) ) ;
387
463
Ok ( ( ) )
388
464
}
@@ -423,13 +499,17 @@ impl ser::Serializer for Serializer {
423
499
state => panic ! ( "expected key, found {:?}" , state) ,
424
500
} ;
425
501
502
+ println ! ( "SERIALIZED KEY: {:?}" , & key) ;
503
+
426
504
try!( value. serialize ( self ) ) ;
427
505
428
506
let value = match self . state . pop ( ) . unwrap ( ) {
429
507
State :: Bson ( value) => value,
430
508
state => panic ! ( "expected value, found {:?}" , state) ,
431
509
} ;
432
510
511
+ println ! ( "SERIALIZED VALUE: {:?}" , & value) ;
512
+
433
513
match * self . state . last_mut ( ) . unwrap ( ) {
434
514
State :: Document ( ref mut values) => { values. insert ( key, value) ; }
435
515
ref state => panic ! ( "expected object, found {:?}" , state) ,
@@ -497,6 +577,7 @@ impl de::Deserializer for Deserializer {
497
577
_ => {
498
578
let doc = value. to_extended_document ( ) ;
499
579
let len = doc. len ( ) ;
580
+ println ! ( "{:?}" , doc) ;
500
581
visitor. visit_map ( MapDeserializer {
501
582
de : self ,
502
583
iter : doc. into_iter ( ) ,
@@ -787,77 +868,6 @@ impl de::Deserialize for Bson {
787
868
fn deserialize < D > ( deserializer : & mut D ) -> Result < Bson , D :: Error >
788
869
where D : de:: Deserializer ,
789
870
{
790
- struct BsonVisitor ;
791
-
792
- impl de:: Visitor for BsonVisitor {
793
- type Value = Bson ;
794
-
795
- #[ inline]
796
- fn visit_bool < E > ( & mut self , value : bool ) -> Result < Bson , E > {
797
- Ok ( Bson :: Boolean ( value) )
798
- }
799
-
800
- #[ inline]
801
- fn visit_i64 < E > ( & mut self , value : i64 ) -> Result < Bson , E > {
802
- Ok ( Bson :: I64 ( value) )
803
- }
804
-
805
- #[ inline]
806
- fn visit_u64 < E > ( & mut self , value : u64 ) -> Result < Bson , E > {
807
- Ok ( Bson :: FloatingPoint ( value as f64 ) )
808
- }
809
-
810
- #[ inline]
811
- fn visit_f64 < E > ( & mut self , value : f64 ) -> Result < Bson , E > {
812
- Ok ( Bson :: FloatingPoint ( value) )
813
- }
814
-
815
- #[ inline]
816
- fn visit_str < E > ( & mut self , value : & str ) -> Result < Bson , E >
817
- where E : de:: Error ,
818
- {
819
- self . visit_string ( String :: from ( value) )
820
- }
821
-
822
- #[ inline]
823
- fn visit_string < E > ( & mut self , value : String ) -> Result < Bson , E > {
824
- Ok ( Bson :: String ( value) )
825
- }
826
-
827
- #[ inline]
828
- fn visit_none < E > ( & mut self ) -> Result < Bson , E > {
829
- Ok ( Bson :: Null )
830
- }
831
-
832
- #[ inline]
833
- fn visit_some < D > ( & mut self , deserializer : & mut D ) -> Result < Bson , D :: Error >
834
- where D : de:: Deserializer ,
835
- {
836
- de:: Deserialize :: deserialize ( deserializer)
837
- }
838
-
839
- #[ inline]
840
- fn visit_unit < E > ( & mut self ) -> Result < Bson , E > {
841
- Ok ( Bson :: Null )
842
- }
843
-
844
- #[ inline]
845
- fn visit_seq < V > ( & mut self , visitor : V ) -> Result < Bson , V :: Error >
846
- where V : de:: SeqVisitor ,
847
- {
848
- let values = try!( de:: impls:: VecVisitor :: new ( ) . visit_seq ( visitor) ) ;
849
- Ok ( Bson :: Array ( values) )
850
- }
851
-
852
- #[ inline]
853
- fn visit_map < V > ( & mut self , visitor : V ) -> Result < Bson , V :: Error >
854
- where V : de:: MapVisitor ,
855
- {
856
- let values = try!( de:: impls:: BTreeMapVisitor :: new ( ) . visit_map ( visitor) ) ;
857
- Ok ( Bson :: from_extended_document ( values. into ( ) ) . unwrap ( ) )
858
- }
859
- }
860
-
861
871
deserializer. visit ( BsonVisitor )
862
872
}
863
873
}
@@ -878,50 +888,3 @@ pub fn from_bson<T>(bson: Bson) -> Result<T, Error>
878
888
let mut de = Deserializer :: new ( bson) ;
879
889
de:: Deserialize :: deserialize ( & mut de)
880
890
}
881
-
882
-
883
- ///////////////
884
- /*
885
- pub struct OrderedMapIteratorVisitor<Iter> {
886
- iter: Iter,
887
- len: Option<usize>,
888
- }
889
-
890
- impl<K, V, Iter> OrderedMapIteratorVisitor<Iter>
891
- where Iter: Iterator<Item=(K, V)>
892
- {
893
- /// Construct a new `MapIteratorVisitor<Iter>`.
894
- #[inline]
895
- pub fn new(iter: Iter, len: Option<usize>) -> MapIteratorVisitor<Iter> {
896
- MapIteratorVisitor {
897
- iter: iter,
898
- len: len,
899
- }
900
- }
901
- }
902
-
903
- impl<K, V, I> MapVisitor for MapIteratorVisitor<I>
904
- where K: Serialize,
905
- V: Serialize,
906
- I: Iterator<Item=(K, V)>,
907
- {
908
- #[inline]
909
- fn visit<S>(&mut self, serializer: &mut S) -> Result<Option<()>, S::Error>
910
- where S: Serializer,
911
- {
912
- match self.iter.next() {
913
- Some((key, value)) => {
914
- let value = try!(serializer.serialize_map_elt(key, value));
915
- Ok(Some(value))
916
- }
917
- None => Ok(None)
918
- }
919
- }
920
-
921
- #[inline]
922
- fn len(&self) -> Option<usize> {
923
- self.len
924
- }
925
- }
926
- */
927
- ///////////////////////////////////////////////////////////////////////////////
0 commit comments