From f41adc8834eb063313d4b85e23b47b411ed5cd28 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Fri, 6 Dec 2024 23:53:32 +0100 Subject: [PATCH 1/3] Remove async-trait --- Cargo.toml | 5 ++--- src/async_std.rs | 14 +++++--------- src/tokio.rs | 14 +++++--------- tests/clamav_client.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fe325e1..9012763 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ exclude = ["clamd", ".github"] tokio = { version = "1.34.0", default-features = false, features = ["fs", "io-util", "net"], optional = true } tokio-stream = { version = "0.1.14", default-features = false, optional = true } async-std = { version = "1.12.0", optional = true } -async-trait = { version = "0.1.77", optional = true } bytes = { version = "1", optional = true } [dev-dependencies] @@ -26,9 +25,9 @@ tokio-util = { version = "0.7.10", features = ["io"] } async-std = { version = "1.12.0", features = ["attributes"] } [features] -tokio = ["dep:async-trait", "dep:tokio"] +tokio = ["dep:tokio"] tokio-stream = ["tokio", "dep:tokio-stream", "dep:bytes"] -async-std = ["dep:async-trait", "dep:async-std", "dep:bytes"] +async-std = ["dep:async-std", "dep:bytes"] [package.metadata.docs.rs] features = ["tokio", "tokio-stream", "async-std"] diff --git a/src/async_std.rs b/src/async_std.rs index b22fd9a..20df9ae 100644 --- a/src/async_std.rs +++ b/src/async_std.rs @@ -5,7 +5,6 @@ use async_std::{ path::Path, stream::{Stream, StreamExt}, }; -use async_trait::async_trait; #[cfg(unix)] use async_std::os::unix::net::UnixStream; @@ -109,31 +108,28 @@ pub struct Socket> { } /// The communication protocol to use -#[async_trait(?Send)] pub trait TransportProtocol { /// Bidirectional stream type Stream: ReadExt + WriteExt + Unpin; /// Converts the protocol instance into the corresponding stream - async fn connect(&self) -> io::Result; + fn connect(&self) -> impl std::future::Future>; } -#[async_trait(?Send)] impl TransportProtocol for Tcp { type Stream = TcpStream; - async fn connect(&self) -> io::Result { - TcpStream::connect(&self.host_address).await + fn connect(&self) -> impl std::future::Future> { + TcpStream::connect(&self.host_address) } } -#[async_trait(?Send)] #[cfg(unix)] impl> TransportProtocol for Socket

{ type Stream = UnixStream; - async fn connect(&self) -> io::Result { - UnixStream::connect(&self.socket_path).await + fn connect(&self) -> impl std::future::Future> { + UnixStream::connect(&self.socket_path) } } diff --git a/src/tokio.rs b/src/tokio.rs index 5355d9d..27be701 100644 --- a/src/tokio.rs +++ b/src/tokio.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use std::path::Path; use tokio::{ fs::File, @@ -112,31 +111,28 @@ pub struct Socket> { } /// The communication protocol to use -#[async_trait(?Send)] pub trait TransportProtocol { /// Bidirectional stream type Stream: AsyncRead + AsyncWrite + Unpin; /// Converts the protocol instance into the corresponding stream - async fn connect(&self) -> io::Result; + fn connect(&self) -> impl std::future::Future>; } -#[async_trait(?Send)] impl TransportProtocol for Tcp { type Stream = TcpStream; - async fn connect(&self) -> io::Result { - TcpStream::connect(&self.host_address).await + fn connect(&self) -> impl std::future::Future> { + TcpStream::connect(&self.host_address) } } -#[async_trait(?Send)] #[cfg(unix)] impl> TransportProtocol for Socket

{ type Stream = UnixStream; - async fn connect(&self) -> io::Result { - UnixStream::connect(&self.socket_path).await + fn connect(&self) -> impl std::future::Future> { + UnixStream::connect(&self.socket_path) } } diff --git a/tests/clamav_client.rs b/tests/clamav_client.rs index c9928c3..a8ff9c3 100644 --- a/tests/clamav_client.rs +++ b/tests/clamav_client.rs @@ -14,6 +14,8 @@ const OK_RESPONSE: &[u8] = b"stream: OK\0"; const OVERSIZED_TEST_FILE_PATH: &str = "tests/data/stream-max-length-test-file.bin"; const SIZE_LIMIT_EXCEEDED_ERROR_RESPONSE: &[u8] = b"INSTREAM size limit exceeded. ERROR\0"; +fn assert_implements_send_sync(_t: T) {} + mod lib_tests { use super::*; @@ -345,6 +347,24 @@ mod tokio_tests { assert_eq!(&response, SIZE_LIMIT_EXCEEDED_ERROR_RESPONSE); assert_eq!(clamav_client::clean(&response), Ok(false)); } + + #[tokio::test] + async fn async_tokio_implements_send_sync_trait() { + trait _AssertSendSync: Send + Sync {} + + impl _AssertSendSync for clamav_client::tokio::Tcp<&str> {} + assert_implements_send_sync(clamav_client::tokio::scan_buffer(&[], CLAMD_HOST_TCP, None)); + + #[cfg(unix)] + { + impl _AssertSendSync for clamav_client::tokio::Socket<&str> {} + assert_implements_send_sync(clamav_client::tokio::scan_buffer( + &[], + CLAMD_HOST_SOCKET, + None, + )); + } + } } #[cfg(feature = "tokio-stream")] @@ -643,6 +663,28 @@ mod async_std_tests { assert_eq!(&response, SIZE_LIMIT_EXCEEDED_ERROR_RESPONSE); assert_eq!(clamav_client::clean(&response), Ok(false)); } + + #[async_std::test] + async fn async_std_implements_send_sync_trait() { + trait _AssertSendSync: Send + Sync {} + + impl _AssertSendSync for clamav_client::async_std::Tcp<&str> {} + assert_implements_send_sync(clamav_client::async_std::scan_buffer( + &[], + CLAMD_HOST_TCP, + None, + )); + + #[cfg(unix)] + { + impl _AssertSendSync for clamav_client::async_std::Socket<&str> {} + assert_implements_send_sync(clamav_client::async_std::scan_buffer( + &[], + CLAMD_HOST_SOCKET, + None, + )); + } + } } #[cfg(feature = "async-std")] From 86aa095ac5877a9bfe91119d99a4f3155d71edba Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Sat, 7 Dec 2024 00:13:12 +0100 Subject: [PATCH 2/3] Add contributor --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5de41ab..117bfb2 100644 --- a/README.md +++ b/README.md @@ -228,3 +228,4 @@ Contributions are welcome! - [Paul Makles](https://github.com/insertish) - [Sean Clarke](https://github.com/SeanEClarke) - [Kanji Tanaka](https://github.com/kaicoh) +- [Raui Ghazaleh](https://github.com/raui100) From a143a5e2c3cb8c7f953f688ee1894119c499c740 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Sat, 7 Dec 2024 00:14:09 +0100 Subject: [PATCH 3/3] Bump version --- Cargo.toml | 2 +- README.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9012763..e58ab36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clamav-client" -version = "1.0.1" +version = "2.0.0" edition = "2021" rust-version = "1.63.0" authors = ["Thorsten Blum "] diff --git a/README.md b/README.md index 117bfb2..4d0dc66 100644 --- a/README.md +++ b/README.md @@ -15,28 +15,28 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -clamav-client = "1.0.1" +clamav-client = "2.0.0" ``` To use the `async` functions in `clamav_client::tokio`, add this to your `Cargo.toml`: ```toml [dependencies] -clamav-client = { version = "1.0.1", features = ["tokio"] } +clamav-client = { version = "2.0.0", features = ["tokio"] } ``` To scan Tokio streams, enable the `tokio-stream` feature instead and add this to your `Cargo.toml`: ```toml [dependencies] -clamav-client = { version = "1.0.1", features = ["tokio-stream"] } +clamav-client = { version = "2.0.0", features = ["tokio-stream"] } ``` Support for `async-std` is also available by enabling the `async-std` feature: ```toml [dependencies] -clamav-client = { version = "1.0.1", features = ["async-std"] } +clamav-client = { version = "2.0.0", features = ["async-std"] } ``` ## Migrations