From 08f25ccb08ee834b60d61388991cbe71fdcaf0f6 Mon Sep 17 00:00:00 2001 From: Gunnar Noordbruis <13799935+GunnarMorrigan@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:21:28 +0100 Subject: [PATCH] Removed async_trait dep Removing this will prepare this crate for async fn in trait release --- Cargo.lock | 12 ------------ Cargo.toml | 1 - README.md | 4 ---- examples/smol_tls/src/main.rs | 2 -- examples/tokio_tls/src/main.rs | 3 --- src/lib.rs | 10 ++-------- src/mqtt_handler.rs | 2 +- src/tests/tls.rs | 2 +- 8 files changed, 4 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 051a3c2..80c02c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,17 +139,6 @@ version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "atomic-waker" version = "1.1.0" @@ -493,7 +482,6 @@ version = "0.2.2" dependencies = [ "async-channel", "async-rustls", - "async-trait", "bytes", "futures", "pretty_assertions", diff --git a/Cargo.toml b/Cargo.toml index 4c52950..51ff445 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,6 @@ tracing = { version = "0.1.39", optional = true } async-channel = "1.9.0" #async-mutex = "1.4.0" futures = { version = "0.3.28", default-features = false, features = ["std", "async-await"] } -async-trait = "0.1.74" # quic feature flag # quinn = {version = "0.9.0", optional = true } diff --git a/README.md b/README.md index 84dea34..8df9d47 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,10 @@ use mqrstt::{ AsyncEventHandler, smol::NetworkStatus, }; -use async_trait::async_trait; use bytes::Bytes; pub struct PingPong { pub client: MqttClient, } -#[async_trait] impl AsyncEventHandler for PingPong { // Handlers only get INCOMING packets. This can change later. async fn handle(&mut self, event: packets::Packet) -> () { @@ -125,13 +123,11 @@ use mqrstt::{ tokio::NetworkStatus, }; use tokio::time::Duration; -use async_trait::async_trait; use bytes::Bytes; pub struct PingPong { pub client: MqttClient, } -#[async_trait] impl AsyncEventHandler for PingPong { // Handlers only get INCOMING packets. This can change later. async fn handle(&mut self, event: packets::Packet) -> () { diff --git a/examples/smol_tls/src/main.rs b/examples/smol_tls/src/main.rs index 6cb5cb9..02fb550 100644 --- a/examples/smol_tls/src/main.rs +++ b/examples/smol_tls/src/main.rs @@ -1,6 +1,5 @@ use std::{io::{BufReader, Cursor}, sync::Arc}; -use async_trait::async_trait; use mqrstt::{MqttClient, AsyncEventHandler, packets::{self, Packet}, ConnectOptions, new_smol, NetworkStatus}; use rustls::{RootCertStore, OwnedTrustAnchor, ClientConfig, Certificate, ServerName}; @@ -12,7 +11,6 @@ pub struct PingPong { pub client: MqttClient, } -#[async_trait] impl AsyncEventHandler for PingPong { // Handlers only get INCOMING packets. This can change later. async fn handle(&mut self, event: packets::Packet) -> () { diff --git a/examples/tokio_tls/src/main.rs b/examples/tokio_tls/src/main.rs index 999b106..14e2e00 100644 --- a/examples/tokio_tls/src/main.rs +++ b/examples/tokio_tls/src/main.rs @@ -1,10 +1,8 @@ use std::{io::{BufReader, Cursor}, sync::Arc, time::Duration}; -use async_trait::async_trait; use mqrstt::{MqttClient, AsyncEventHandler, packets::{self, Packet}, ConnectOptions, NetworkStatus, new_tokio}; use tokio_rustls::rustls::{ClientConfig, RootCertStore, OwnedTrustAnchor, Certificate, ServerName}; - pub const EMQX_CERT: &[u8] = include_bytes!("broker.emqx.io-ca.crt"); @@ -12,7 +10,6 @@ pub struct PingPong { pub client: MqttClient, } -#[async_trait] impl AsyncEventHandler for PingPong { // Handlers only get INCOMING packets. This can change later. async fn handle(&mut self, event: packets::Packet) -> () { diff --git a/src/lib.rs b/src/lib.rs index 6ccd9aa..1b3a1fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,6 @@ //! AsyncEventHandler, //! smol::NetworkStatus, //! }; -//! use async_trait::async_trait; //! //! smol::block_on(async { //! let options = ConnectOptions::new("mqrsttSmolExample".to_string()); @@ -91,7 +90,6 @@ //! tokio::NetworkStatus, //! }; //! use tokio::time::Duration; -//! use async_trait::async_trait; //! //! #[tokio::main] //! async fn main() { @@ -201,6 +199,7 @@ pub mod state; pub use client::MqttClient; pub use connect_options::ConnectOptions; +use futures::Future; pub use mqtt_handler::MqttHandler; use packets::{Connect, ConnectProperties, Packet}; @@ -211,9 +210,8 @@ pub mod tests; /// This guarantees that the end user has handlded the packet. /// Trait for async mutable access to handler. /// Usefull when you have a single handler -#[async_trait::async_trait] pub trait AsyncEventHandler { - async fn handle(&mut self, incoming_packet: Packet); + fn handle(&mut self, incoming_packet: Packet) -> impl Future + Send + Sync; } pub trait EventHandler { @@ -224,7 +222,6 @@ pub trait EventHandler { /// This handler performs no operations on incoming messages. pub struct NOP{} -#[async_trait::async_trait] impl AsyncEventHandler for NOP{ async fn handle(&mut self, _: Packet){ @@ -368,7 +365,6 @@ mod lib_test { packets::{self, Packet}, AsyncEventHandler, ConnectOptions, EventHandler, MqttClient, }; - use async_trait::async_trait; use bytes::Bytes; use packets::QoS; @@ -377,7 +373,6 @@ mod lib_test { } #[cfg(any(feature = "smol", feature = "tokio"))] - #[async_trait] impl AsyncEventHandler for PingPong { async fn handle(&mut self, event: packets::Packet) -> () { match event { @@ -561,7 +556,6 @@ mod lib_test { } } - #[async_trait] impl AsyncEventHandler for PingResp { async fn handle(&mut self, event: packets::Packet) -> () { use Packet::*; diff --git a/src/mqtt_handler.rs b/src/mqtt_handler.rs index fdb7284..0212bc2 100644 --- a/src/mqtt_handler.rs +++ b/src/mqtt_handler.rs @@ -255,7 +255,7 @@ mod handler_tests { }; pub struct Nop {} - #[async_trait::async_trait] + impl AsyncEventHandler for Nop { async fn handle(&mut self, _event: Packet) {} } diff --git a/src/tests/tls.rs b/src/tests/tls.rs index 38272f8..955a14b 100644 --- a/src/tests/tls.rs +++ b/src/tests/tls.rs @@ -44,7 +44,7 @@ pub mod tests { let client_certs = rustls_pemfile::certs(&mut BufReader::new(Cursor::new(client_cert_info))).unwrap(); let client_cert_chain = client_certs.into_iter().map(Certificate).collect(); - config.with_single_cert(client_cert_chain, rustls::PrivateKey(key))? + config.with_client_auth_cert(client_cert_chain, rustls::PrivateKey(key))? } None => config.with_no_client_auth(), };