From 8e03927af38ae2cecd766f14405b1184f303b31f Mon Sep 17 00:00:00 2001 From: theodore Date: Sat, 21 Dec 2024 21:40:52 +0100 Subject: [PATCH] chore(clippy): fix lints --- crates/socketioxide-redis/Cargo.toml | 5 +---- crates/socketioxide-redis/src/drivers/mod.rs | 13 ++++-------- .../socketioxide-redis/src/drivers/redis.rs | 6 +++--- crates/socketioxide-redis/src/lib.rs | 2 +- crates/socketioxide-redis/tests/broadcast.rs | 2 +- crates/socketioxide-redis/tests/rooms.rs | 20 ++++--------------- 6 files changed, 14 insertions(+), 34 deletions(-) diff --git a/crates/socketioxide-redis/Cargo.toml b/crates/socketioxide-redis/Cargo.toml index d496ac66..659eeb55 100644 --- a/crates/socketioxide-redis/Cargo.toml +++ b/crates/socketioxide-redis/Cargo.toml @@ -41,7 +41,4 @@ socketioxide = { path = "../socketioxide", features = [ tracing-subscriber.workspace = true [features] -__test_harness = [ - "socketioxide/__test_harness", - "socketioxide-core/__test_harness", -] +__test_harness = ["socketioxide-core/__test_harness"] diff --git a/crates/socketioxide-redis/src/drivers/mod.rs b/crates/socketioxide-redis/src/drivers/mod.rs index 40dc372d..fa0a3e29 100644 --- a/crates/socketioxide-redis/src/drivers/mod.rs +++ b/crates/socketioxide-redis/src/drivers/mod.rs @@ -78,13 +78,14 @@ pub mod test { use super::MessageStream; + type ChanItem = (String, Vec); pub struct StubDriver { - tx: mpsc::Sender<(String, Vec)>, + tx: mpsc::Sender, handlers: Arc>>>>, num_serv: u16, } async fn pipe_handers( - mut rx: mpsc::Receiver<(String, Vec)>, + mut rx: mpsc::Receiver, handlers: Arc>>>>, ) { while let Some((chan, data)) = rx.recv().await { @@ -96,13 +97,7 @@ pub mod test { } } impl StubDriver { - pub fn new( - num_serv: u16, - ) -> ( - Self, - mpsc::Receiver<(String, Vec)>, - mpsc::Sender<(String, Vec)>, - ) { + pub fn new(num_serv: u16) -> (Self, mpsc::Receiver, mpsc::Sender) { let (tx, rx) = mpsc::channel(255); // driver emitter let (tx1, rx1) = mpsc::channel(255); // driver receiver let handlers = Arc::new(RwLock::new(HashMap::<_, mpsc::Sender>>::new())); diff --git a/crates/socketioxide-redis/src/drivers/redis.rs b/crates/socketioxide-redis/src/drivers/redis.rs index 612665cb..992096cc 100644 --- a/crates/socketioxide-redis/src/drivers/redis.rs +++ b/crates/socketioxide-redis/src/drivers/redis.rs @@ -15,9 +15,9 @@ use super::{Driver, MessageStream}; #[derive(Debug)] pub struct RedisError(redis::RedisError); -impl Into for RedisError { - fn into(self) -> AdapterError { - AdapterError::from(Box::new(self.0) as Box) +impl From for AdapterError { + fn from(err: RedisError) -> Self { + AdapterError::from(Box::new(err.0) as Box) } } impl From for RedisError { diff --git a/crates/socketioxide-redis/src/lib.rs b/crates/socketioxide-redis/src/lib.rs index 644450f8..ff2ecc32 100644 --- a/crates/socketioxide-redis/src/lib.rs +++ b/crates/socketioxide-redis/src/lib.rs @@ -351,7 +351,7 @@ impl CoreAdapter for RedisAdapter { } async fn close(&self) -> Result<(), Self::Error> { - self.driver.unsubscribe(&self.local.path()).await?; + self.driver.unsubscribe(self.local.path()).await?; Ok(()) } diff --git a/crates/socketioxide-redis/tests/broadcast.rs b/crates/socketioxide-redis/tests/broadcast.rs index d1baebd3..08c48eda 100644 --- a/crates/socketioxide-redis/tests/broadcast.rs +++ b/crates/socketioxide-redis/tests/broadcast.rs @@ -33,7 +33,7 @@ pub async fn broadcast_rooms() { let handler = |room: &'static str, to: &'static str| { move |socket: SocketRef<_>| async move { // delay to ensure all socket/servers are connected - socket.join(room).await.unwrap(); + socket.join(room); tokio::time::sleep(tokio::time::Duration::from_millis(5)).await; socket.to(to).emit("test", room).await.unwrap(); } diff --git a/crates/socketioxide-redis/tests/rooms.rs b/crates/socketioxide-redis/tests/rooms.rs index ad14b1fa..aa8ce2a8 100644 --- a/crates/socketioxide-redis/tests/rooms.rs +++ b/crates/socketioxide-redis/tests/rooms.rs @@ -5,11 +5,7 @@ mod fixture; #[tokio::test] pub async fn all_rooms() { let [io1, io2, io3] = fixture::spawn_servers(); - let handler = |rooms: &'static [&'static str]| { - move |socket: SocketRef<_>| async move { - socket.join(rooms).await.unwrap(); - } - }; + let handler = |rooms: &'static [&'static str]| move |socket: SocketRef<_>| socket.join(rooms); io1.ns("/", handler(&["room1", "room2"])); io2.ns("/", handler(&["room2", "room3"])); @@ -25,7 +21,7 @@ pub async fn all_rooms() { timeout_rcv!(&mut rx2); // Connect "/" packet timeout_rcv!(&mut rx3); // Connect "/" packet - const ROOMS: [&'static str; 3] = ["room1", "room2", "room3"]; + const ROOMS: [&str; 3] = ["room1", "room2", "room3"]; for io in [io1, io2, io3] { let mut rooms = io.rooms().await.unwrap(); rooms.sort(); @@ -38,11 +34,7 @@ pub async fn all_rooms() { } #[tokio::test] pub async fn add_sockets() { - let handler = |room: &'static str| { - move |socket: SocketRef<_>| async move { - socket.join(room).await.unwrap(); - } - }; + let handler = |room: &'static str| move |socket: SocketRef<_>| socket.join(room); let [io1, io2] = fixture::spawn_servers(); io1.ns("/", handler("room1")); @@ -64,11 +56,7 @@ pub async fn add_sockets() { #[tokio::test] pub async fn del_sockets() { - let handler = |rooms: &'static [&'static str]| { - move |socket: SocketRef<_>| async move { - socket.join(rooms).await.unwrap(); - } - }; + let handler = |rooms: &'static [&'static str]| move |socket: SocketRef<_>| socket.join(rooms); let [io1, io2] = fixture::spawn_servers(); io1.ns("/", handler(&["room1", "room2"]));