@@ -4,6 +4,7 @@ use crate::flash::Location;
44use crate :: struct_accessors:: Getter ;
55use crate :: struct_accessors:: Setter ;
66use crate :: struct_accessors:: make_accessors;
7+ use crate :: struct_accessors:: make_bitfield_serde;
78use crate :: types:: Error ;
89use crate :: types:: Result ;
910use core:: convert:: TryFrom ;
@@ -751,95 +752,6 @@ impl ValueOrLocation {
751752 }
752753}
753754
754- // XXX: If I move this to struct_accessors, it doesn't work anymore.
755-
756- /// A variant of the make_accessors macro for modular_bitfields.
757- macro_rules! make_bitfield_serde { (
758- $( #[ $struct_meta: meta] ) *
759- $struct_vis: vis
760- struct $StructName: ident {
761- $(
762- $( #[ $field_meta: meta] ) *
763- $field_vis: vis
764- $field_name: ident
765- $( || $( #[ $serde_field_orig_meta: meta] ) * $serde_ty: ty : $field_orig_ty: ty) ?
766- $( : $field_ty: ty) ?
767- $( | $getter_vis: vis get $field_user_ty: ty $( : $setter_vis: vis set $field_setter_user_ty: ty) ?) ?
768- ) ,* $( , ) ?
769- }
770- ) => {
771- $( #[ $struct_meta] ) *
772- $struct_vis
773- struct $StructName {
774- $(
775- $( #[ $field_meta] ) *
776- $field_vis
777- $( $field_name : $field_ty, ) ?
778- $( $field_name : $field_orig_ty, ) ?
779- ) *
780- }
781-
782- impl $StructName {
783- pub fn builder( ) -> Self {
784- Self :: new( ) // NOT default
785- }
786- pub fn build( & self ) -> Self {
787- self . clone( )
788- }
789- }
790-
791- #[ cfg( feature = "serde" ) ]
792- #[ allow( dead_code) ]
793- impl $StructName {
794- $(
795- paste:: paste!{
796- $(
797- #[ allow( non_snake_case) ]
798- pub ( crate ) fn [ <serde_ $field_name>] ( self : & ' _ Self )
799- -> Result <$field_ty> {
800- Ok ( self . $field_name( ) )
801- }
802- ) ?
803- $(
804- #[ allow( non_snake_case) ]
805- pub ( crate ) fn [ <serde_ $field_name>] ( self : & ' _ Self )
806- -> Result <$serde_ty> {
807- Ok ( self . $field_name( ) . into( ) )
808- }
809- ) ?
810- $(
811- #[ allow( non_snake_case) ]
812- pub ( crate ) fn [ <serde_with_ $field_name>] ( self : & mut Self , value: $field_ty) -> & mut Self {
813- self . [ <set_ $field_name>] ( value. into( ) ) ;
814- self
815- }
816- ) ?
817- $(
818- #[ allow( non_snake_case) ]
819- pub ( crate ) fn [ <serde_with_ $field_name>] ( self : & mut Self , value: $serde_ty) -> & mut Self {
820- self . [ <set_ $field_name>] ( value. into( ) ) ;
821- self
822- }
823- ) ?
824- }
825- ) *
826- }
827-
828- #[ cfg( feature = "serde" ) ]
829- paste:: paste! {
830- #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
831- #[ cfg_attr( feature = "serde" , serde( deny_unknown_fields) ) ]
832- #[ cfg_attr( feature = "schemars" , derive( schemars:: JsonSchema ) ) ]
833- #[ cfg_attr( feature = "serde" , serde( rename = "" $StructName) ) ]
834- pub ( crate ) struct [ <Serde $StructName>] {
835- $(
836- $( pub $field_name : <$field_ty as Specifier >:: InOut , ) ?
837- $( $( #[ $serde_field_orig_meta] ) * pub $field_name : $serde_ty, ) ?
838- ) *
839- }
840- }
841- } }
842-
843755#[ derive(
844756 Debug , PartialEq , Eq , FromPrimitive , Clone , Copy , BitfieldSpecifier ,
845757) ]
0 commit comments