Skip to content

Commit

Permalink
Removed async_trait dep
Browse files Browse the repository at this point in the history
Removing this will prepare this crate for async fn in trait release
  • Loading branch information
GunnarMorrigan committed Dec 16, 2023
1 parent 6471fb8 commit 08f25cc
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 32 deletions.
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> () {
Expand Down Expand Up @@ -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) -> () {
Expand Down
2 changes: 0 additions & 2 deletions examples/smol_tls/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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) -> () {
Expand Down
3 changes: 0 additions & 3 deletions examples/tokio_tls/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
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");


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) -> () {
Expand Down
10 changes: 2 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//! AsyncEventHandler,
//! smol::NetworkStatus,
//! };
//! use async_trait::async_trait;
//!
//! smol::block_on(async {
//! let options = ConnectOptions::new("mqrsttSmolExample".to_string());
Expand Down Expand Up @@ -91,7 +90,6 @@
//! tokio::NetworkStatus,
//! };
//! use tokio::time::Duration;
//! use async_trait::async_trait;
//!
//! #[tokio::main]
//! async fn main() {
Expand Down Expand Up @@ -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};

Expand All @@ -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<Output = ()> + Send + Sync;
}

pub trait EventHandler {
Expand All @@ -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){

Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -561,7 +556,6 @@ mod lib_test {
}
}

#[async_trait]
impl AsyncEventHandler for PingResp {
async fn handle(&mut self, event: packets::Packet) -> () {
use Packet::*;
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down

0 comments on commit 08f25cc

Please sign in to comment.