Skip to content

Commit 7606706

Browse files
committed
non-generic single fields
1 parent ae359bd commit 7606706

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/generate/register.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -659,21 +659,34 @@ pub fn fields(
659659
Ident::new("FieldWriterSafe", span)
660660
};
661661

662+
let (offset, gen_offset) = if field_dim.is_some() {
663+
(quote! { O }, quote! {, const O: u8 })
664+
} else {
665+
(util::unsuffixed(offset as u64), quote! {})
666+
};
662667
let proxy = if width == 1 {
663-
quote! { crate::BitWriter<'a, #rty, #name_uc_spec, #name_pc_aw, O> }
668+
quote! { crate::BitWriter<'a, #rty, #name_uc_spec, #name_pc_aw, #offset> }
664669
} else {
665670
let width = &util::unsuffixed(width as _);
666-
quote! { crate::#wproxy<'a, #rty, #name_uc_spec, #fty, #name_pc_aw, #width, O> }
671+
quote! { crate::#wproxy<'a, #rty, #name_uc_spec, #fty, #name_pc_aw, #width, #offset> }
667672
};
668673
mod_items.extend(quote! {
669674
#[doc = #writerdoc]
670-
pub type #name_pc_w<'a, const O: u8> = #proxy;
675+
pub type #name_pc_w<'a #gen_offset> = #proxy;
671676
});
672677
}
673678
if !proxy_items.is_empty() {
674-
mod_items.extend(quote! {
675-
impl<'a, const O: u8> #name_pc_w<'a, O> {
676-
#proxy_items
679+
mod_items.extend(if field_dim.is_some() {
680+
quote! {
681+
impl<'a, const O: u8> #name_pc_w<'a, O> {
682+
#proxy_items
683+
}
684+
}
685+
} else {
686+
quote! {
687+
impl<'a> #name_pc_w<'a> {
688+
#proxy_items
689+
}
677690
}
678691
});
679692
}
@@ -710,11 +723,10 @@ pub fn fields(
710723
}
711724
} else {
712725
let doc = description_with_bits(description_raw, offset, width);
713-
let offset = util::unsuffixed(offset as u64);
714726
w_impl_items.extend(quote! {
715727
#[doc = #doc]
716728
#inline
717-
pub fn #name_sc(&mut self) -> #name_pc_w<#offset> {
729+
pub fn #name_sc(&mut self) -> #name_pc_w {
718730
#name_pc_w::new(self)
719731
}
720732
});

0 commit comments

Comments
 (0)