Skip to content

Commit c3bcc1f

Browse files
bors[bot]burrbull
andcommitted
Merge #374
374: From instead of ToBits r=therealprof a=burrbull r? @therealprof Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents e2e0004 + 2d21197 commit c3bcc1f

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/generate/generic.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ pub trait ResetValue {
2121
fn reset_value() -> Self::Type;
2222
}
2323

24-
///Converting enumerated values to bits
25-
pub trait ToBits<N> {
26-
///Conversion method
27-
fn _bits(&self) -> N;
28-
}
29-
3024
///This structure provides volatile access to register
3125
pub struct Reg<U, REG> {
3226
register: vcell::VolatileCell<U>,
@@ -181,11 +175,11 @@ where
181175
impl<U, T, FI> PartialEq<FI> for R<U, T>
182176
where
183177
U: PartialEq,
184-
FI: ToBits<U>
178+
FI: Copy+Into<U>
185179
{
186180
#[inline(always)]
187181
fn eq(&self, other: &FI) -> bool {
188-
self.bits.eq(&other._bits())
182+
self.bits.eq(&(*other).into())
189183
}
190184
}
191185

src/generate/register.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,8 @@ pub fn fields(
475475
///Writes `variant` to the field
476476
#[inline(always)]
477477
pub fn variant(self, variant: #pc_w) -> &'a mut W {
478-
use crate::ToBits;
479478
#unsafety {
480-
self.#bits(variant._bits())
479+
self.#bits(variant.into())
481480
}
482481
}
483482
});
@@ -657,10 +656,10 @@ fn add_from_variants(mod_items: &mut Vec<Tokens>, variants: &Vec<Variant>, pc: &
657656
});
658657

659658
mod_items.push(quote! {
660-
impl crate::ToBits<#fty> for #pc {
659+
impl From<#pc> for #fty {
661660
#[inline(always)]
662-
fn _bits(&self) -> #fty {
663-
match *self {
661+
fn from(variant: #pc) -> Self {
662+
match variant {
664663
#(#arms),*
665664
}
666665
}

0 commit comments

Comments
 (0)