@@ -7,7 +7,7 @@ use crate::de::{
7
7
} ;
8
8
9
9
#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
10
- use crate :: de:: { MapAccess , Unexpected } ;
10
+ use crate :: de:: { MapAccess , StdError , Unexpected } ;
11
11
12
12
#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
13
13
pub use self :: content:: {
@@ -2587,17 +2587,43 @@ where
2587
2587
}
2588
2588
2589
2589
#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2590
- pub struct FlatMapDeserializer < ' a , ' de : ' a , E > (
2591
- pub & ' a mut Vec < Option < ( Content < ' de > , Content < ' de > ) > > ,
2592
- pub PhantomData < E > ,
2593
- ) ;
2590
+ #[ cfg_attr( any( feature = "std" , feature = "alloc" ) , derive( Debug ) ) ]
2591
+ pub enum FlatMapDeserializerError {
2592
+ Message ( String ) ,
2593
+ NoVariantFoundInFlattenedData ( & ' static str ) ,
2594
+ }
2594
2595
2595
2596
#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2596
- impl < ' a , ' de , E > FlatMapDeserializer < ' a , ' de , E >
2597
- where
2598
- E : Error ,
2599
- {
2600
- fn deserialize_other < V > ( ) -> Result < V , E > {
2597
+ impl Display for FlatMapDeserializerError {
2598
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2599
+ match self {
2600
+ FlatMapDeserializerError :: Message ( msg) => write ! ( f, "{}" , msg) ,
2601
+ FlatMapDeserializerError :: NoVariantFoundInFlattenedData ( name) => {
2602
+ write ! ( f, "no variant of enum {} found in flattened data" , name)
2603
+ }
2604
+ }
2605
+ }
2606
+ }
2607
+
2608
+ #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2609
+ impl StdError for FlatMapDeserializerError { }
2610
+
2611
+ #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2612
+ impl Error for FlatMapDeserializerError {
2613
+ fn custom < T > ( msg : T ) -> Self
2614
+ where
2615
+ T : Display ,
2616
+ {
2617
+ FlatMapDeserializerError :: Message ( msg. to_string ( ) )
2618
+ }
2619
+ }
2620
+
2621
+ #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2622
+ pub struct FlatMapDeserializer < ' a , ' de : ' a > ( pub & ' a mut Vec < Option < ( Content < ' de > , Content < ' de > ) > > ) ;
2623
+
2624
+ #[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2625
+ impl < ' a , ' de > FlatMapDeserializer < ' a , ' de > {
2626
+ fn deserialize_other < V > ( ) -> Result < V , FlatMapDeserializerError > {
2601
2627
Err ( Error :: custom ( "can only flatten structs and maps" ) )
2602
2628
}
2603
2629
}
@@ -2617,11 +2643,8 @@ macro_rules! forward_to_deserialize_other {
2617
2643
}
2618
2644
2619
2645
#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
2620
- impl < ' a , ' de , E > Deserializer < ' de > for FlatMapDeserializer < ' a , ' de , E >
2621
- where
2622
- E : Error ,
2623
- {
2624
- type Error = E ;
2646
+ impl < ' a , ' de > Deserializer < ' de > for FlatMapDeserializer < ' a , ' de > {
2647
+ type Error = FlatMapDeserializerError ;
2625
2648
2626
2649
fn deserialize_any < V > ( self , visitor : V ) -> Result < V :: Value , Self :: Error >
2627
2650
where
@@ -2645,10 +2668,9 @@ where
2645
2668
}
2646
2669
}
2647
2670
2648
- Err ( Error :: custom ( format_args ! (
2649
- "no variant of enum {} found in flattened data" ,
2650
- name
2651
- ) ) )
2671
+ Err ( FlatMapDeserializerError :: NoVariantFoundInFlattenedData (
2672
+ name,
2673
+ ) )
2652
2674
}
2653
2675
2654
2676
fn deserialize_map < V > ( self , visitor : V ) -> Result < V :: Value , Self :: Error >
0 commit comments