Skip to content

Commit 29129c0

Browse files
bors[bot]couchand
andauthored
Merge #476
476: Fix derivedFrom enumerated values r=therealprof a=couchand derivedFrom FieldReaders should always be a type alias for the base FieldReader, rather than each their own newtype. ~I believe this fixes #474, however I'm having trouble getting a working development environment set up for the `esp32` project.~ ~@MabezDev, would you mind giving this a spin and posting a diff of the generated code?~ Figured out my issue, the generated code looks good, e.g.: ```diff diff --git a/src/rtccntl/wdtconfig0.rs b/src/rtccntl/wdtconfig0.rs index 6851bff..089e4e1 100644 --- a/src/rtccntl/wdtconfig0.rs +++ b/src/rtccntl/wdtconfig0.rs @@ -186,19 +186,7 @@ impl<'a> WDT_STG0_W<'a> { #[doc = ""] pub type WDT_STG1_A = WDT_STG0_A; #[doc = "Field `WDT_STG1` reader - "] -pub struct WDT_STG1_R(crate::FieldReader<u8, WDT_STG1_A>); -impl WDT_STG1_R { - pub(crate) fn new(bits: u8) -> Self { - WDT_STG1_R(crate::FieldReader::new(bits)) - } -} -impl core::ops::Deref for WDT_STG1_R { - type Target = crate::FieldReader<u8, WDT_STG1_A>; - #[inline(always)] - fn deref(&self) -> &Self::Target { - &self.0 - } -} +pub type WDT_STG1_R = WDT_STG0_R; #[doc = "Field `WDT_STG1` writer - "] pub struct WDT_STG1_W<'a> { w: &'a mut W, ``` Co-authored-by: Andrew Dona-Couch <[email protected]>
2 parents 1a2bf65 + 5700351 commit 29129c0

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/generate/register.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -430,30 +430,15 @@ pub fn fields(
430430
evs_r = Some(evs.clone());
431431

432432
if let Some(base) = base {
433-
let pc = util::replace_suffix(base.field, "");
434-
let pc = pc.to_sanitized_upper_case();
435-
let base_pc_r = Ident::new(&(pc + "_A"), span);
436-
derive_from_base(mod_items, &base, &name_pc_a, &base_pc_r, &description);
433+
let pc_orig = util::replace_suffix(base.field, "");
437434

438-
mod_items.extend(quote! {
439-
#[doc = #readerdoc]
440-
pub struct #name_pc_r(crate::FieldReader<#fty, #name_pc_a>);
441-
442-
impl #name_pc_r {
443-
pub(crate) fn new(bits: #fty) -> Self {
444-
#name_pc_r(crate::FieldReader::new(bits))
445-
}
446-
}
435+
let pc = pc_orig.to_sanitized_upper_case();
436+
let base_pc_a = Ident::new(&(pc + "_A"), span);
437+
derive_from_base(mod_items, &base, &name_pc_a, &base_pc_a, &description);
447438

448-
impl core::ops::Deref for #name_pc_r {
449-
type Target = crate::FieldReader<#fty, #name_pc_a>;
450-
451-
#[inline(always)]
452-
fn deref(&self) -> &Self::Target {
453-
&self.0
454-
}
455-
}
456-
});
439+
let pc = pc_orig.to_sanitized_upper_case();
440+
let base_pc_r = Ident::new(&(pc + "_R"), span);
441+
derive_from_base(mod_items, &base, &name_pc_r, &base_pc_r, &readerdoc);
457442
} else {
458443
let has_reserved_variant = evs.values.len() != (1 << width);
459444
let variants = Variant::from_enumerated_values(evs)?;

0 commit comments

Comments
 (0)