From 8fd359a5340b23b8138a5f5e85d448c8eb1c0583 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 10 Apr 2024 21:26:28 +0200 Subject: [PATCH] fix clippy --- host/src/adapter.rs | 4 ++-- host/src/channel_manager.rs | 5 ++--- host/src/connection.rs | 2 +- host/src/l2cap.rs | 21 ++++++++++++--------- host/tests/l2cap.rs | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/host/src/adapter.rs b/host/src/adapter.rs index 50f3709..7e10374 100644 --- a/host/src/adapter.rs +++ b/host/src/adapter.rs @@ -151,8 +151,8 @@ where C: AsyncCmd, T: ControllerCmdAsync, { - let ret = cmd.exec(&self.controller).await?; - Ok(ret) + cmd.exec(&self.controller).await?; + Ok(()) } pub(crate) async fn connect(&self, config: &ConnectConfig<'_>) -> Result, AdapterError> diff --git a/host/src/channel_manager.rs b/host/src/channel_manager.rs index 2dd543f..3064e50 100644 --- a/host/src/channel_manager.rs +++ b/host/src/channel_manager.rs @@ -632,7 +632,7 @@ impl CreditFlowControl { } fn process(&mut self) -> Option { - let flow = match self.policy { + match self.policy { CreditFlowPolicy::Every(count) => { if self.received >= count { let amount = self.received; @@ -653,8 +653,7 @@ impl CreditFlowControl { None } } - }; - flow + } } } diff --git a/host/src/connection.rs b/host/src/connection.rs index aab0c86..3d208e6 100644 --- a/host/src/connection.rs +++ b/host/src/connection.rs @@ -122,7 +122,7 @@ impl<'d> Connection<'d> { where T: ControllerCmdAsync, { - let ret = adapter + adapter .async_command(LeConnUpdate::new( self.info.handle, params.min_connection_interval.into(), diff --git a/host/src/l2cap.rs b/host/src/l2cap.rs index 7170028..3f7348a 100644 --- a/host/src/l2cap.rs +++ b/host/src/l2cap.rs @@ -31,14 +31,14 @@ pub struct AssembledPacket<'d> { } impl<'d> AssembledPacket<'d> { - pub fn new(packet: Packet<'d>, initial: usize) -> Self { + pub(crate) fn new(packet: Packet<'d>, initial: usize) -> Self { Self { packet, written: initial, } } - pub fn write(&mut self, data: &[u8]) -> Result<(), Error> { + pub(crate) fn write(&mut self, data: &[u8]) -> Result<(), Error> { if self.written + data.len() > self.packet.len() { return Err(Error::InsufficientSpace); } @@ -47,11 +47,11 @@ impl<'d> AssembledPacket<'d> { Ok(()) } - pub fn len(&self) -> usize { + pub(crate) fn len(&self) -> usize { self.written } - pub fn finalize(self, header: L2capHeader) -> Result<(L2capHeader, Packet<'d>), Error> { + pub(crate) fn finalize(self, header: L2capHeader) -> Result<(L2capHeader, Packet<'d>), Error> { if header.length as usize != self.written { return Err(Error::InvalidValue); } @@ -63,6 +63,11 @@ impl<'d> AssembledPacket<'d> { pub struct PacketReassembly<'d, const CONNS: usize> { handles: RefCell<[Option<(ConnHandle, L2capHeader, AssembledPacket<'d>)>; CONNS]>, } +impl<'d, const CONNS: usize> Default for PacketReassembly<'d, CONNS> { + fn default() -> Self { + Self::new() + } +} impl<'d, const CONNS: usize> PacketReassembly<'d, CONNS> { const EMPTY: Option<(ConnHandle, L2capHeader, AssembledPacket<'d>)> = None; @@ -80,11 +85,9 @@ impl<'d, const CONNS: usize> PacketReassembly<'d, CONNS> { let mut state = self.handles.borrow_mut(); // Sanity check - for entry in state.iter() { - if let Some(entry) = entry { - if entry.0 == handle { - return Err(Error::InvalidState); - } + for entry in state.iter().flatten() { + if entry.0 == handle { + return Err(Error::InvalidState); } } diff --git a/host/tests/l2cap.rs b/host/tests/l2cap.rs index f50295e..30702bf 100644 --- a/host/tests/l2cap.rs +++ b/host/tests/l2cap.rs @@ -196,8 +196,8 @@ async fn l2cap_connection_oriented_channels() { match tokio::time::timeout(Duration::from_secs(30), local).await { Ok(_) => { - let _ = central.await.unwrap().unwrap(); - let _ = peripheral.await.unwrap().unwrap(); + central.await.unwrap().unwrap(); + peripheral.await.unwrap().unwrap(); println!("Test completed successfully"); } Err(e) => {