diff --git a/src/generate/generic.rs b/src/generate/generic.rs index 657ccaea..0d98c37d 100644 --- a/src/generate/generic.rs +++ b/src/generate/generic.rs @@ -21,12 +21,6 @@ pub trait ResetValue { fn reset_value() -> Self::Type; } -///Converting enumerated values to bits -pub trait ToBits { - ///Conversion method - fn _bits(&self) -> N; -} - ///This structure provides volatile access to register pub struct Reg { register: vcell::VolatileCell, @@ -181,11 +175,11 @@ where impl PartialEq for R where U: PartialEq, - FI: ToBits + FI: Copy+Into { #[inline(always)] fn eq(&self, other: &FI) -> bool { - self.bits.eq(&other._bits()) + self.bits.eq(&(*other).into()) } } diff --git a/src/generate/register.rs b/src/generate/register.rs index 5493f5ec..64e96b50 100644 --- a/src/generate/register.rs +++ b/src/generate/register.rs @@ -475,9 +475,8 @@ pub fn fields( ///Writes `variant` to the field #[inline(always)] pub fn variant(self, variant: #pc_w) -> &'a mut W { - use crate::ToBits; #unsafety { - self.#bits(variant._bits()) + self.#bits(variant.into()) } } }); @@ -657,10 +656,10 @@ fn add_from_variants(mod_items: &mut Vec, variants: &Vec, pc: & }); mod_items.push(quote! { - impl crate::ToBits<#fty> for #pc { + impl From<#pc> for #fty { #[inline(always)] - fn _bits(&self) -> #fty { - match *self { + fn from(variant: #pc) -> Self { + match variant { #(#arms),* } }