@@ -12,8 +12,9 @@ use crate::de::{MapAccess, Unexpected};
1212#[ cfg( any( feature = "std" , feature = "alloc" ) ) ]
1313pub use self :: content:: {
1414 Content , ContentDeserializer , ContentRefDeserializer , EnumDeserializer ,
15- InternallyTaggedUnitVisitor , TagContentOtherField , TagContentOtherFieldVisitor ,
16- TagOrContentField , TagOrContentFieldVisitor , TaggedContentVisitor , UntaggedUnitVisitor ,
15+ InternallyTaggedUnitVisitor , NoSeqTaggedContentVisitor , TagContentOtherField ,
16+ TagContentOtherFieldVisitor , TagOrContentField , TagOrContentFieldVisitor , TaggedContentVisitor ,
17+ UntaggedUnitVisitor ,
1718} ;
1819
1920pub use crate :: seed:: InPlaceSeed ;
@@ -206,7 +207,6 @@ mod content {
206207 // This issue is tracking making some of this stuff public:
207208 // https://github.com/serde-rs/serde/issues/741
208209
209- use crate :: de:: Error ;
210210 use crate :: lib:: * ;
211211
212212 use crate :: actually_private;
@@ -830,6 +830,40 @@ mod content {
830830 }
831831 }
832832
833+ /// Used by generated code to deserialize an internally tagged enum without sequence format.
834+ ///
835+ /// Captures map from the original deserializer and searches
836+ /// a tag in it.
837+ ///
838+ /// Not public API.
839+ pub struct NoSeqTaggedContentVisitor < T > ( TaggedContentVisitor < T > ) ;
840+
841+ impl < T > NoSeqTaggedContentVisitor < T > {
842+ /// Visitor for the content of an internally tagged enum with the given
843+ /// tag name.
844+ pub fn new ( name : & ' static str , expecting : & ' static str ) -> Self {
845+ Self ( TaggedContentVisitor :: new ( name, expecting) )
846+ }
847+ }
848+
849+ impl < ' de , T > Visitor < ' de > for NoSeqTaggedContentVisitor < T >
850+ where
851+ T : Deserialize < ' de > ,
852+ {
853+ type Value = ( T , Content < ' de > ) ;
854+
855+ fn expecting ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
856+ self . 0 . expecting ( fmt)
857+ }
858+
859+ fn visit_map < M > ( self , map : M ) -> Result < Self :: Value , M :: Error >
860+ where
861+ M : MapAccess < ' de > ,
862+ {
863+ self . 0 . visit_map ( map)
864+ }
865+ }
866+
833867 /// Used by generated code to deserialize an internally tagged enum.
834868 ///
835869 /// Captures map or sequence from the original deserializer and searches
@@ -840,18 +874,16 @@ mod content {
840874 tag_name : & ' static str ,
841875 expecting : & ' static str ,
842876 value : PhantomData < T > ,
843- use_seq : bool ,
844877 }
845878
846879 impl < T > TaggedContentVisitor < T > {
847880 /// Visitor for the content of an internally tagged enum with the given
848881 /// tag name.
849- pub fn new ( name : & ' static str , expecting : & ' static str , use_seq : bool ) -> Self {
882+ pub fn new ( name : & ' static str , expecting : & ' static str ) -> Self {
850883 TaggedContentVisitor {
851884 tag_name : name,
852885 expecting,
853886 value : PhantomData ,
854- use_seq,
855887 }
856888 }
857889 }
@@ -870,18 +902,14 @@ mod content {
870902 where
871903 S : SeqAccess < ' de > ,
872904 {
873- if self . use_seq {
874- let tag = match tri ! ( seq. next_element( ) ) {
875- Some ( tag) => tag,
876- None => {
877- return Err ( de:: Error :: missing_field ( self . tag_name ) ) ;
878- }
879- } ;
880- let rest = de:: value:: SeqAccessDeserializer :: new ( seq) ;
881- Ok ( ( tag, tri ! ( Content :: deserialize( rest) ) ) )
882- } else {
883- Err ( Error :: invalid_type ( Unexpected :: Seq , & self ) )
884- }
905+ let tag = match tri ! ( seq. next_element( ) ) {
906+ Some ( tag) => tag,
907+ None => {
908+ return Err ( de:: Error :: missing_field ( self . tag_name ) ) ;
909+ }
910+ } ;
911+ let rest = de:: value:: SeqAccessDeserializer :: new ( seq) ;
912+ Ok ( ( tag, tri ! ( Content :: deserialize( rest) ) ) )
885913 }
886914
887915 fn visit_map < M > ( self , mut map : M ) -> Result < Self :: Value , M :: Error >
0 commit comments