@@ -719,12 +719,7 @@ impl<'de, E: Error> SumAccess<'de> for NoneAccess<E> {
719719impl < ' de , E : Error > VariantAccess < ' de > for NoneAccess < E > {
720720 type Error = E ;
721721 fn deserialize_seed < T : DeserializeSeed < ' de > > ( self , seed : T ) -> Result < T :: Output , Self :: Error > {
722- use crate :: algebraic_value:: de:: * ;
723- seed. deserialize ( ValueDeserializer :: new ( crate :: AlgebraicValue :: unit ( ) ) )
724- . map_err ( |err| match err {
725- ValueDeserializeError :: MismatchedType => E :: custom ( "mismatched type" ) ,
726- ValueDeserializeError :: Custom ( err) => E :: custom ( err) ,
727- } )
722+ seed. deserialize ( UnitAccess :: new ( ) )
728723 }
729724}
730725
@@ -753,3 +748,126 @@ impl<'de, D: Deserializer<'de>> VariantAccess<'de> for SomeAccess<D> {
753748 seed. deserialize ( self . 0 )
754749 }
755750}
751+
752+ pub struct UnitAccess < E > ( PhantomData < E > ) ;
753+
754+ impl < E : Error > UnitAccess < E > {
755+ /// Returns a new [`UnitAccess`].
756+ pub fn new ( ) -> Self {
757+ Self ( PhantomData )
758+ }
759+ }
760+
761+ impl < E : Error > Default for UnitAccess < E > {
762+ fn default ( ) -> Self {
763+ Self :: new ( )
764+ }
765+ }
766+
767+ impl < ' de , E : Error > SeqProductAccess < ' de > for UnitAccess < E > {
768+ type Error = E ;
769+
770+ fn next_element_seed < T : DeserializeSeed < ' de > > ( & mut self , _seed : T ) -> Result < Option < T :: Output > , Self :: Error > {
771+ Ok ( None )
772+ }
773+ }
774+
775+ impl < ' de , E : Error > NamedProductAccess < ' de > for UnitAccess < E > {
776+ type Error = E ;
777+
778+ fn get_field_ident < V : FieldNameVisitor < ' de > > ( & mut self , _visitor : V ) -> Result < Option < V :: Output > , Self :: Error > {
779+ Ok ( None )
780+ }
781+
782+ fn get_field_value_seed < T : DeserializeSeed < ' de > > ( & mut self , _seed : T ) -> Result < T :: Output , Self :: Error > {
783+ unreachable ! ( )
784+ }
785+ }
786+
787+ impl < ' de , E : Error > Deserializer < ' de > for UnitAccess < E > {
788+ type Error = E ;
789+
790+ fn deserialize_product < V : ProductVisitor < ' de > > ( self , visitor : V ) -> Result < V :: Output , Self :: Error > {
791+ visitor. visit_seq_product ( self )
792+ }
793+
794+ fn deserialize_sum < V : SumVisitor < ' de > > ( self , _visitor : V ) -> Result < V :: Output , Self :: Error > {
795+ Err ( E :: custom ( "invalid type" ) )
796+ }
797+
798+ fn deserialize_bool ( self ) -> Result < bool , Self :: Error > {
799+ Err ( E :: custom ( "invalid type" ) )
800+ }
801+
802+ fn deserialize_u8 ( self ) -> Result < u8 , Self :: Error > {
803+ Err ( E :: custom ( "invalid type" ) )
804+ }
805+
806+ fn deserialize_u16 ( self ) -> Result < u16 , Self :: Error > {
807+ Err ( E :: custom ( "invalid type" ) )
808+ }
809+
810+ fn deserialize_u32 ( self ) -> Result < u32 , Self :: Error > {
811+ Err ( E :: custom ( "invalid type" ) )
812+ }
813+
814+ fn deserialize_u64 ( self ) -> Result < u64 , Self :: Error > {
815+ Err ( E :: custom ( "invalid type" ) )
816+ }
817+
818+ fn deserialize_u128 ( self ) -> Result < u128 , Self :: Error > {
819+ Err ( E :: custom ( "invalid type" ) )
820+ }
821+
822+ fn deserialize_u256 ( self ) -> Result < u256 , Self :: Error > {
823+ Err ( E :: custom ( "invalid type" ) )
824+ }
825+
826+ fn deserialize_i8 ( self ) -> Result < i8 , Self :: Error > {
827+ Err ( E :: custom ( "invalid type" ) )
828+ }
829+
830+ fn deserialize_i16 ( self ) -> Result < i16 , Self :: Error > {
831+ Err ( E :: custom ( "invalid type" ) )
832+ }
833+
834+ fn deserialize_i32 ( self ) -> Result < i32 , Self :: Error > {
835+ Err ( E :: custom ( "invalid type" ) )
836+ }
837+
838+ fn deserialize_i64 ( self ) -> Result < i64 , Self :: Error > {
839+ Err ( E :: custom ( "invalid type" ) )
840+ }
841+
842+ fn deserialize_i128 ( self ) -> Result < i128 , Self :: Error > {
843+ Err ( E :: custom ( "invalid type" ) )
844+ }
845+
846+ fn deserialize_i256 ( self ) -> Result < i256 , Self :: Error > {
847+ Err ( E :: custom ( "invalid type" ) )
848+ }
849+
850+ fn deserialize_f32 ( self ) -> Result < f32 , Self :: Error > {
851+ Err ( E :: custom ( "invalid type" ) )
852+ }
853+
854+ fn deserialize_f64 ( self ) -> Result < f64 , Self :: Error > {
855+ Err ( E :: custom ( "invalid type" ) )
856+ }
857+
858+ fn deserialize_str < V : SliceVisitor < ' de , str > > ( self , _visitor : V ) -> Result < V :: Output , Self :: Error > {
859+ Err ( E :: custom ( "invalid type" ) )
860+ }
861+
862+ fn deserialize_bytes < V : SliceVisitor < ' de , [ u8 ] > > ( self , _visitor : V ) -> Result < V :: Output , Self :: Error > {
863+ Err ( E :: custom ( "invalid type" ) )
864+ }
865+
866+ fn deserialize_array_seed < V : ArrayVisitor < ' de , T :: Output > , T : DeserializeSeed < ' de > + Clone > (
867+ self ,
868+ _visitor : V ,
869+ _seed : T ,
870+ ) -> Result < V :: Output , Self :: Error > {
871+ Err ( E :: custom ( "invalid type" ) )
872+ }
873+ }
0 commit comments