From 58a268850f34b660c9c71a3442b7cc70d21944da Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 9 Sep 2019 21:19:01 -0400 Subject: Clippy. --- src/pipe/addr.rs | 4 ++-- src/pipe/ctrl_pipe.rs | 14 ++++++------- src/pipe/ext_reg.rs | 2 +- src/pipe/pck_size.rs | 54 ++++++++++++++++++++++++------------------------- src/pipe/status_bk.rs | 2 +- src/pipe/status_pipe.rs | 2 +- 6 files changed, 39 insertions(+), 39 deletions(-) (limited to 'src/pipe') diff --git a/src/pipe/addr.rs b/src/pipe/addr.rs index b3548cf..d71ee2d 100644 --- a/src/pipe/addr.rs +++ b/src/pipe/addr.rs @@ -17,7 +17,7 @@ pub struct W { } impl Addr { - pub fn read(&self) -> R { + pub fn read(self) -> R { R { bits: self.0 } } @@ -89,7 +89,7 @@ impl<'a> AddrW<'a> { pub unsafe fn bits(self, v: u32) -> &'a mut W { // Address must be 32-bit aligned. cf ยง32.8.7.2 of SAMD21 data // sheet. - assert!((v & 0x3) == 0); + debug_assert!(v.trailing_zeros() >= 2); self.w.bits = v; self.w } diff --git a/src/pipe/ctrl_pipe.rs b/src/pipe/ctrl_pipe.rs index 91235cd..360a0e7 100644 --- a/src/pipe/ctrl_pipe.rs +++ b/src/pipe/ctrl_pipe.rs @@ -16,7 +16,7 @@ pub struct W { } impl CtrlPipe { - pub fn read(&self) -> R { + pub fn read(self) -> R { R { bits: self.0 } } @@ -142,8 +142,8 @@ impl<'a> PErMaxW<'a> { pub unsafe fn bits(self, v: u8) -> &'a mut W { const POS: u8 = 12; const MASK: u8 = 0xf; - self.w.bits &= !((MASK as u16) << POS); - self.w.bits |= ((v & MASK) as u16) << POS; + self.w.bits &= !(u16::from(MASK) << POS); + self.w.bits |= u16::from(v & MASK) << POS; self.w } @@ -159,8 +159,8 @@ impl<'a> PEpNumW<'a> { pub unsafe fn bits(self, v: u8) -> &'a mut W { const POS: u8 = 8; const MASK: u8 = 0xf; - self.w.bits &= !((MASK as u16) << POS); - self.w.bits |= ((v & MASK) as u16) << POS; + self.w.bits &= !(u16::from(MASK) << POS); + self.w.bits |= u16::from(v & MASK) << POS; self.w } @@ -176,8 +176,8 @@ impl<'a> PDAddrW<'a> { pub unsafe fn bits(self, v: u8) -> &'a mut W { const POS: u8 = 0; const MASK: u8 = 0x3f; - self.w.bits &= !((MASK as u16) << POS); - self.w.bits |= ((v & MASK) as u16) << POS; + self.w.bits &= !(u16::from(MASK) << POS); + self.w.bits |= u16::from(v & MASK) << POS; self.w } diff --git a/src/pipe/ext_reg.rs b/src/pipe/ext_reg.rs index 9778f1b..cd2a8dc 100644 --- a/src/pipe/ext_reg.rs +++ b/src/pipe/ext_reg.rs @@ -17,7 +17,7 @@ pub(crate) struct W { } impl ExtReg { - pub fn read(&self) -> R { + pub fn read(self) -> R { R { bits: self.0 } } diff --git a/src/pipe/pck_size.rs b/src/pipe/pck_size.rs index c95140d..48441a8 100644 --- a/src/pipe/pck_size.rs +++ b/src/pipe/pck_size.rs @@ -17,7 +17,7 @@ pub(crate) struct W { } impl PckSize { - pub fn read(&self) -> R { + pub fn read(self) -> R { R { bits: self.0 } } @@ -137,8 +137,8 @@ pub(crate) enum SizeR { } impl SizeR { - pub fn bits(&self) -> u8 { - match *self { + pub fn bits(self) -> u8 { + match self { Self::Bytes8 => 0x0, Self::Bytes16 => 0x1, Self::Bytes32 => 0x2, @@ -150,29 +150,29 @@ impl SizeR { } } - fn is_bytes8(&self) -> bool { - *self == Self::Bytes8 + fn is_bytes8(self) -> bool { + self == Self::Bytes8 } - fn is_bytes16(&self) -> bool { - *self == Self::Bytes16 + fn is_bytes16(self) -> bool { + self == Self::Bytes16 } - fn is_bytes32(&self) -> bool { - *self == Self::Bytes32 + fn is_bytes32(self) -> bool { + self == Self::Bytes32 } - fn is_bytes64(&self) -> bool { - *self == Self::Bytes64 + fn is_bytes64(self) -> bool { + self == Self::Bytes64 } - fn is_bytes128(&self) -> bool { - *self == Self::Bytes128 + fn is_bytes128(self) -> bool { + self == Self::Bytes128 } - fn is_bytes256(&self) -> bool { - *self == Self::Bytes256 + fn is_bytes256(self) -> bool { + self == Self::Bytes256 } - fn is_bytes512(&self) -> bool { - *self == Self::Bytes512 + fn is_bytes512(self) -> bool { + self == Self::Bytes512 } - fn is_bytes1024(&self) -> bool { - *self == Self::Bytes1024 + fn is_bytes1024(self) -> bool { + self == Self::Bytes1024 } } @@ -281,8 +281,8 @@ pub(crate) enum SizeW { Bytes1024, } impl SizeW { - pub fn bits(&self) -> u8 { - match *self { + pub fn bits(self) -> u8 { + match self { Self::Bytes8 => 0, Self::Bytes16 => 1, Self::Bytes32 => 2, @@ -303,8 +303,8 @@ impl<'a> _SizeW<'a> { pub unsafe fn bits(self, v: u8) -> &'a mut W { const POS: u8 = 28; const MASK: u8 = 0x7; - self.w.bits &= !((MASK as u32) << POS); - self.w.bits |= ((v & MASK) as u32) << POS; + self.w.bits &= !(u32::from(MASK) << POS); + self.w.bits |= u32::from(v & MASK) << POS; self.w } @@ -354,8 +354,8 @@ impl<'a> MultiPacketSizeW<'a> { const POS: u8 = 14; const MASK: u16 = 0x3fff; - self.w.bits &= !((MASK as u32) << POS); - self.w.bits |= ((v & MASK) as u32) << POS; + self.w.bits &= !(u32::from(MASK) << POS); + self.w.bits |= u32::from(v & MASK) << POS; self.w } } @@ -371,8 +371,8 @@ impl<'a> ByteCountW<'a> { const POS: u8 = 0; const MASK: u16 = 0x3fff; - self.w.bits &= !((MASK as u32) << POS); - self.w.bits |= ((v & MASK) as u32) << POS; + self.w.bits &= !(u32::from(MASK) << POS); + self.w.bits |= u32::from(v & MASK) << POS; self.w } } diff --git a/src/pipe/status_bk.rs b/src/pipe/status_bk.rs index 489fc62..50a549c 100644 --- a/src/pipe/status_bk.rs +++ b/src/pipe/status_bk.rs @@ -17,7 +17,7 @@ pub(crate) struct W { } impl StatusBk { - pub fn read(&self) -> R { + pub fn read(self) -> R { R { bits: self.0 } } diff --git a/src/pipe/status_pipe.rs b/src/pipe/status_pipe.rs index be135c5..d7db9c6 100644 --- a/src/pipe/status_pipe.rs +++ b/src/pipe/status_pipe.rs @@ -15,7 +15,7 @@ pub(crate) struct W { } impl StatusPipe { - pub fn read(&self) -> R { + pub fn read(self) -> R { R { bits: self.0 } } -- cgit v1.2.3