Skip to content

Commit bf93c62

Browse files
committed
From instead of Into
1 parent 9191c13 commit bf93c62

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/generate/generic.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,12 @@ impl<REG: RegisterSpec> R<REG> {
269269
impl<REG: RegisterSpec, FI> PartialEq<FI> for R<REG>
270270
where
271271
REG::Ux: PartialEq,
272-
FI: Copy + Into<REG::Ux>,
272+
FI: Copy,
273+
REG::Ux: From<FI>
273274
{
274275
#[inline(always)]
275276
fn eq(&self, other: &FI) -> bool {
276-
self.bits.eq(&(*other).into())
277+
self.bits.eq(&REG::Ux::from(*other))
277278
}
278279
}
279280

@@ -360,21 +361,23 @@ where
360361
impl<U, FI> PartialEq<FI> for FieldReader<U, FI>
361362
where
362363
U: PartialEq,
363-
FI: Copy + Into<U>,
364+
FI: Copy,
365+
U: From<FI>,
364366
{
365367
#[inline(always)]
366368
fn eq(&self, other: &FI) -> bool {
367-
self.bits.eq(&(*other).into())
369+
self.bits.eq(&U::from(*other))
368370
}
369371
}
370372

371373
impl<FI> PartialEq<FI> for BitReader<FI>
372374
where
373-
FI: Copy + Into<bool>,
375+
FI: Copy,
376+
bool: From<FI>,
374377
{
375378
#[inline(always)]
376379
fn eq(&self, other: &FI) -> bool {
377-
self.bits.eq(&(*other).into())
380+
self.bits.eq(&bool::from(*other))
378381
}
379382
}
380383

@@ -405,7 +408,7 @@ pub struct Unsafe;
405408
pub struct FieldWriterRaw<'a, U, REG, N, FI, Safety, const WI: u8, const O: u8>
406409
where
407410
REG: Writable + RegisterSpec<Ux = U>,
408-
FI: Into<N>,
411+
N: From<FI>,
409412
{
410413
pub(crate) w: &'a mut REG::Writer,
411414
_field: marker::PhantomData<(N, FI, Safety)>,
@@ -415,7 +418,7 @@ impl<'a, U, REG, N, FI, Safety, const WI: u8, const O: u8>
415418
FieldWriterRaw<'a, U, REG, N, FI, Safety, WI, O>
416419
where
417420
REG: Writable + RegisterSpec<Ux = U>,
418-
FI: Into<N>,
421+
N: From<FI>,
419422
{
420423
/// Creates a new instance of the writer
421424
#[allow(unused)]
@@ -432,7 +435,7 @@ where
432435
pub struct BitWriterRaw<'a, U, REG, FI, M, const O: u8>
433436
where
434437
REG: Writable + RegisterSpec<Ux = U>,
435-
FI: Into<bool>,
438+
bool: From<FI>,
436439
{
437440
pub(crate) w: &'a mut REG::Writer,
438441
_field: marker::PhantomData<(FI, M)>,
@@ -441,7 +444,7 @@ where
441444
impl<'a, U, REG, FI, M, const O: u8> BitWriterRaw<'a, U, REG, FI, M, O>
442445
where
443446
REG: Writable + RegisterSpec<Ux = U>,
444-
FI: Into<bool>,
447+
bool: From<FI>,
445448
{
446449
/// Creates a new instance of the writer
447450
#[allow(unused)]
@@ -464,7 +467,7 @@ pub type FieldWriterSafe<'a, U, REG, N, FI, const WI: u8, const O: u8> =
464467
impl<'a, U, REG, N, FI, const WI: u8, const OF: u8> FieldWriter<'a, U, REG, N, FI, WI, OF>
465468
where
466469
REG: Writable + RegisterSpec<Ux = U>,
467-
FI: Into<N>,
470+
N: From<FI>,
468471
{
469472
/// Field width
470473
pub const WIDTH: u8 = WI;
@@ -473,7 +476,7 @@ where
473476
impl<'a, U, REG, N, FI, const WI: u8, const OF: u8> FieldWriterSafe<'a, U, REG, N, FI, WI, OF>
474477
where
475478
REG: Writable + RegisterSpec<Ux = U>,
476-
FI: Into<N>,
479+
N: From<FI>,
477480
{
478481
/// Field width
479482
pub const WIDTH: u8 = WI;
@@ -490,7 +493,7 @@ macro_rules! bit_proxy {
490493
impl<'a, U, REG, FI, const OF: u8> $writer<'a, U, REG, FI, OF>
491494
where
492495
REG: Writable + RegisterSpec<Ux = U>,
493-
FI: Into<bool>,
496+
bool: From<FI>,
494497
{
495498
/// Field width
496499
pub const WIDTH: u8 = 1;
@@ -504,7 +507,7 @@ macro_rules! impl_bit_proxy {
504507
where
505508
REG: Writable + RegisterSpec<Ux = U>,
506509
U: RawReg,
507-
FI: Into<bool>,
510+
bool: From<FI>,
508511
{
509512
/// Writes bit to the field
510513
#[inline(always)]
@@ -516,7 +519,7 @@ macro_rules! impl_bit_proxy {
516519
/// Writes `variant` to the field
517520
#[inline(always)]
518521
pub fn variant(self, variant: FI) -> &'a mut REG::Writer {
519-
self.bit(variant.into())
522+
self.bit(bool::from(variant))
520523
}
521524
}
522525
};
@@ -534,7 +537,7 @@ impl<'a, U, REG, N, FI, const WI: u8, const OF: u8> FieldWriter<'a, U, REG, N, F
534537
where
535538
REG: Writable + RegisterSpec<Ux = U>,
536539
U: RawReg + From<N>,
537-
FI: Into<N>,
540+
N: From<FI>,
538541
{
539542
/// Writes raw bits to the field
540543
///
@@ -550,14 +553,14 @@ where
550553
/// Writes `variant` to the field
551554
#[inline(always)]
552555
pub fn variant(self, variant: FI) -> &'a mut REG::Writer {
553-
unsafe { self.bits(variant.into()) }
556+
unsafe { self.bits(N::from(variant)) }
554557
}
555558
}
556559
impl<'a, U, REG, N, FI, const WI: u8, const OF: u8> FieldWriterSafe<'a, U, REG, N, FI, WI, OF>
557560
where
558561
REG: Writable + RegisterSpec<Ux = U>,
559562
U: RawReg + From<N>,
560-
FI: Into<N>,
563+
N: From<FI>,
561564
{
562565
/// Writes raw bits to the field
563566
#[inline(always)]
@@ -569,7 +572,7 @@ where
569572
/// Writes `variant` to the field
570573
#[inline(always)]
571574
pub fn variant(self, variant: FI) -> &'a mut REG::Writer {
572-
self.bits(variant.into())
575+
self.bits(N::from(variant))
573576
}
574577
}
575578

@@ -585,7 +588,7 @@ impl<'a, U, REG, FI, const OF: u8> BitWriter<'a, U, REG, FI, OF>
585588
where
586589
REG: Writable + RegisterSpec<Ux = U>,
587590
U: RawReg,
588-
FI: Into<bool>,
591+
bool: From<FI>,
589592
{
590593
/// Sets the field bit
591594
#[inline(always)]
@@ -603,7 +606,7 @@ impl<'a, U, REG, FI, const OF: u8> BitWriter1S<'a, U, REG, FI, OF>
603606
where
604607
REG: Writable + RegisterSpec<Ux = U>,
605608
U: RawReg,
606-
FI: Into<bool>,
609+
bool: From<FI>,
607610
{
608611
/// Sets the field bit
609612
#[inline(always)]
@@ -616,7 +619,7 @@ impl<'a, U, REG, FI, const OF: u8> BitWriter0C<'a, U, REG, FI, OF>
616619
where
617620
REG: Writable + RegisterSpec<Ux = U>,
618621
U: RawReg,
619-
FI: Into<bool>,
622+
bool: From<FI>,
620623
{
621624
/// Clears the field bit
622625
#[inline(always)]
@@ -629,7 +632,7 @@ impl<'a, U, REG, FI, const OF: u8> BitWriter1C<'a, U, REG, FI, OF>
629632
where
630633
REG: Writable + RegisterSpec<Ux = U>,
631634
U: RawReg,
632-
FI: Into<bool>,
635+
bool: From<FI>,
633636
{
634637
///Clears the field bit by passing one
635638
#[inline(always)]
@@ -642,7 +645,7 @@ impl<'a, U, REG, FI, const OF: u8> BitWriter0S<'a, U, REG, FI, OF>
642645
where
643646
REG: Writable + RegisterSpec<Ux = U>,
644647
U: RawReg,
645-
FI: Into<bool>,
648+
bool: From<FI>,
646649
{
647650
///Sets the field bit by passing zero
648651
#[inline(always)]
@@ -655,7 +658,7 @@ impl<'a, U, REG, FI, const OF: u8> BitWriter1T<'a, U, REG, FI, OF>
655658
where
656659
REG: Writable + RegisterSpec<Ux = U>,
657660
U: RawReg,
658-
FI: Into<bool>,
661+
bool: From<FI>,
659662
{
660663
///Toggle the field bit by passing one
661664
#[inline(always)]
@@ -668,7 +671,7 @@ impl<'a, U, REG, FI, const OF: u8> BitWriter0T<'a, U, REG, FI, OF>
668671
where
669672
REG: Writable + RegisterSpec<Ux = U>,
670673
U: RawReg,
671-
FI: Into<bool>,
674+
bool: From<FI>,
672675
{
673676
///Toggle the field bit by passing zero
674677
#[inline(always)]

0 commit comments

Comments
 (0)