diff --git a/Cargo.lock b/Cargo.lock index 826ae32..8a692ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -246,7 +246,7 @@ dependencies = [ [[package]] name = "mqtt-client" -version = "2.0.2" +version = "3.0.0" dependencies = [ "crossbeam", "rumqttc", diff --git a/Cargo.toml b/Cargo.toml index 575587e..940494c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mqtt-client" -version = "2.0.2" +version = "3.0.0" edition = "2021" [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 17ed006..54d3c3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,8 @@ pub mod mqtt_client { pub use crossbeam::channel::{Receiver, Sender}; pub use rumqttc::QoS; - pub trait MqttTool { - fn new(client: Client, tx: Sender) -> Self; + pub trait MqttTool { + fn new(client: Client, tx: Sender, config: S) -> Self; fn run(&mut self, rx: Receiver); } @@ -21,7 +21,7 @@ pub mod mqtt_client { pub qos: QoS, } - pub fn run(host: String, port: u16, client: String, user: String, pass: String) { + pub fn run>(host: String, port: u16, client: String, user: String, pass: String, config: S) where S: 'static { let (tx_sender, tx_recever) = unbounded::(); let (rx_sender, rx_recever) = unbounded::(); @@ -49,7 +49,7 @@ pub mod mqtt_client { let mqtt = thread::Builder::new() .name("mqtt".to_string()) .spawn(move || { - handeler::(connection, rx_sender); + handeler::(connection, rx_sender); }); match mqtt { Err(_n) => println!("ERROR: mqtt client: failed to create mqtt thread"), @@ -60,7 +60,7 @@ pub mod mqtt_client { let tool_runner = thread::Builder::new() .name("tool runner".to_string()) .spawn(move || { - let mut tool = T::new(client, tx_sender); + let mut tool = T::new(client, tx_sender, config); tool.run(rx_recever); println!("WARN : rool_runner: tool has ended"); }); @@ -94,7 +94,7 @@ pub mod mqtt_client { } } - pub(self) fn handeler(mut connection: Connection, rx: Sender) { + pub(self) fn handeler>(mut connection: Connection, rx: Sender) { for (_i, notification) in connection.iter().enumerate() { let mut delay: bool = false; match notification {