@@ -563,6 +563,7 @@ pub fn fields(
563563 if can_write {
564564 let new_pc_aw = Ident :: new ( & ( name_pc. clone ( ) + "_AW" ) , span) ;
565565 let name_pc_w = Ident :: new ( & ( name_pc. clone ( ) + "_W" ) , span) ;
566+ #[ cfg( feature = "const-generic" ) ]
566567 let name_pc_cgw = Ident :: new ( & ( name_pc. clone ( ) + "_CGW" ) , span) ;
567568
568569 let mut proxy_items = TokenStream :: new ( ) ;
@@ -641,6 +642,7 @@ pub fn fields(
641642 }
642643
643644 let mut proxy_items_fa = TokenStream :: new ( ) ;
645+ #[ cfg( feature = "const-generic" ) ]
644646 let mut proxy_items_cg = TokenStream :: new ( ) ;
645647 if field_dim. is_some ( ) {
646648 proxy_items_fa. extend ( quote ! {
@@ -651,6 +653,7 @@ pub fn fields(
651653 self . w
652654 }
653655 } ) ;
656+ #[ cfg( feature="const-generic" ) ]
654657 proxy_items_cg. extend ( quote ! {
655658 ///Writes raw bits to the field
656659 #inline
@@ -682,13 +685,17 @@ pub fn fields(
682685 } ) ;
683686 }
684687
688+ #[ cfg( feature = "const-generic" ) ]
685689 let mut cgdoc = String :: new ( ) ;
686690 let doc = if let Some ( ( _, _, _, _, suffixes_str) ) = & field_dim {
687- cgdoc = format ! (
688- "Fields `{}` const generic writer - {}" ,
689- util:: replace_suffix( & f. name, suffixes_str) ,
690- description
691- ) ;
691+ #[ cfg( feature = "const-generic" ) ]
692+ {
693+ cgdoc = format ! (
694+ "Fields `{}` const generic writer - {}" ,
695+ util:: replace_suffix( & f. name, suffixes_str) ,
696+ description
697+ ) ;
698+ }
692699 format ! (
693700 "Fields `{}` writer - {}" ,
694701 util:: replace_suffix( & f. name, suffixes_str) ,
@@ -698,8 +705,8 @@ pub fn fields(
698705 format ! ( "Field `{}` writer - {}" , f. name, description)
699706 } ;
700707
701- mod_items . extend ( if field_dim. is_some ( ) {
702- quote ! {
708+ if field_dim. is_some ( ) {
709+ mod_items . extend ( quote ! {
703710 #[ doc = #doc]
704711 pub struct #name_pc_w<' a> {
705712 w: & ' a mut W ,
@@ -710,7 +717,10 @@ pub fn fields(
710717 #proxy_items
711718 #proxy_items_fa
712719 }
720+ } ) ;
713721
722+ #[ cfg( feature = "const-generic" ) ]
723+ mod_items. extend ( quote ! {
714724 #[ doc = #cgdoc]
715725 pub struct #name_pc_cgw<' a, const O : usize > {
716726 w: & ' a mut W ,
@@ -720,9 +730,9 @@ pub fn fields(
720730 #proxy_items
721731 #proxy_items_cg
722732 }
723- }
733+ } ) ;
724734 } else {
725- quote ! {
735+ mod_items . extend ( quote ! {
726736 #[ doc = #doc]
727737 pub struct #name_pc_w<' a> {
728738 w: & ' a mut W ,
@@ -731,8 +741,8 @@ pub fn fields(
731741 impl <' a> #name_pc_w<' a> {
732742 #proxy_items
733743 }
734- }
735- } ) ;
744+ } ) ;
745+ }
736746
737747 if let Some ( ( first, dim, increment, suffixes, suffixes_str) ) = & field_dim {
738748 let offset_calc = calculate_offset ( * first, * increment, offset) ;
@@ -755,6 +765,15 @@ pub fn fields(
755765 & suffix,
756766 ) ;
757767 let sub_offset = util:: unsuffixed ( sub_offset as u64 ) ;
768+ #[ cfg( not( feature = "const-generic" ) ) ]
769+ w_impl_items. extend ( quote ! {
770+ #[ doc = #doc]
771+ #inline
772+ pub fn #name_sc_n( & mut self ) -> #name_pc_w {
773+ #name_pc_w { w: self , offset: #sub_offset }
774+ }
775+ } ) ;
776+ #[ cfg( feature = "const-generic" ) ]
758777 w_impl_items. extend ( quote ! {
759778 #[ doc = #doc]
760779 #inline
0 commit comments