diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2024-04-05 12:02:00 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2024-04-05 15:09:48 +0200 |
commit | c6296007528a595891c30a599aabf3d8d1aa71a9 (patch) | |
tree | 63a7182862f23d7c0aaf8a3ccdbeff82d859c95a | |
parent | 16dd1fe3465fbb90e640975b5aa6de0541d42090 (diff) |
Rename handle functions
We call these "handle" functions only after receiving information from
the server (for now), so there's no decision-process to be implemented
by the user.
There's no need to be async here, and the user cannot return values to
cloudmqtt in this case.
Therefore, we call these functions `on_*` because we simply notify the
user of something that happened.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | cloudmqtt-bin/src/bin/client.rs | 6 | ||||
-rw-r--r-- | src/client/builder.rs | 6 | ||||
-rw-r--r-- | src/client/send.rs | 13 |
3 files changed, 9 insertions, 16 deletions
diff --git a/cloudmqtt-bin/src/bin/client.rs b/cloudmqtt-bin/src/bin/client.rs index 8b044fe..e5f89f2 100644 --- a/cloudmqtt-bin/src/bin/client.rs +++ b/cloudmqtt-bin/src/bin/client.rs @@ -58,11 +58,7 @@ async fn main() { tracing::trace!(?packet, "Received packet") })) .with_handle_qos1_acknowledge(Box::new(|packet| { - async move { - tracing::trace!(?packet, "Acknowledging packet"); - cloudmqtt::client::send::Acknowledge::Yes - } - .boxed() + tracing::trace!(?packet, "Acknowledging packet"); })) .build() .await diff --git a/src/client/builder.rs b/src/client/builder.rs index e8629eb..038cdbd 100644 --- a/src/client/builder.rs +++ b/src/client/builder.rs @@ -10,8 +10,8 @@ use futures::lock::Mutex; use super::send::Callbacks; use super::send::ClientHandlers; -use super::send::HandleQos1AcknowledgeFn; use super::send::OnPacketRecvFn; +use super::send::OnQos1AcknowledgeFn; use super::InnerClient; use super::MqttClient; @@ -31,8 +31,8 @@ impl MqttClientBuilder { self } - pub fn with_handle_qos1_acknowledge(mut self, f: HandleQos1AcknowledgeFn) -> Self { - self.handlers.handle_qos1_acknowledge = f; + pub fn with_handle_qos1_acknowledge(mut self, f: OnQos1AcknowledgeFn) -> Self { + self.handlers.on_qos1_acknowledge = f; self } diff --git a/src/client/send.rs b/src/client/send.rs index 161e130..b81970b 100644 --- a/src/client/send.rs +++ b/src/client/send.rs @@ -215,22 +215,19 @@ pub struct PacketIdentifierExhausted; pub(crate) struct ClientHandlers { pub(crate) on_packet_recv: OnPacketRecvFn, - pub(crate) handle_qos1_acknowledge: HandleQos1AcknowledgeFn, - // handle_qos2_receive: Box<dyn Fn(&crate::packets::MqttPacket) + Send>, - // handle_qos2_complete: Box<dyn Fn(&crate::packets::MqttPacket) + Send>, + pub(crate) on_qos1_acknowledge: OnQos1AcknowledgeFn, + // on_qos2_receive: Box<dyn Fn(&crate::packets::MqttPacket) + Send>, + // on_qos2_complete: Box<dyn Fn(&crate::packets::MqttPacket) + Send>, } pub type OnPacketRecvFn = Box<dyn Fn(&crate::packets::MqttPacket) + Send>; -pub type HandleQos1AcknowledgeFn = Box< - dyn for<'p> Fn(&'p crate::packets::MqttPacket) -> futures::future::BoxFuture<'p, Acknowledge> - + Send, ->; +pub type OnQos1AcknowledgeFn = Box<dyn Fn(&crate::packets::MqttPacket) + Send>; impl Default for ClientHandlers { fn default() -> Self { Self { on_packet_recv: Box::new(|_| ()), - handle_qos1_acknowledge: Box::new(|_| async move { Acknowledge::Yes }.boxed()), + on_qos1_acknowledge: Box::new(|_| ()), } } } |