diff options
author | Marcel Müller <neikos@neikos.email> | 2024-04-05 11:45:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 11:45:58 +0200 |
commit | 16dd1fe3465fbb90e640975b5aa6de0541d42090 (patch) | |
tree | c316ab04d1a28c236524d87371002018338ff592 /src/client/builder.rs | |
parent | c1dd330208fdc4899e9f655cc9d8a308bfc20a32 (diff) | |
parent | cb21213d2167f9dab759ea0d6ecddd8d4ef5262d (diff) |
Merge pull request #280 from matthiasbeyer/client-builder
Client builder
Diffstat (limited to 'src/client/builder.rs')
-rw-r--r-- | src/client/builder.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/client/builder.rs b/src/client/builder.rs new file mode 100644 index 0000000..e8629eb --- /dev/null +++ b/src/client/builder.rs @@ -0,0 +1,54 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +use std::sync::Arc; + +use futures::lock::Mutex; + +use super::send::Callbacks; +use super::send::ClientHandlers; +use super::send::HandleQos1AcknowledgeFn; +use super::send::OnPacketRecvFn; +use super::InnerClient; +use super::MqttClient; + +pub struct MqttClientBuilder { + handlers: ClientHandlers, +} + +impl MqttClientBuilder { + pub(super) fn new() -> Self { + Self { + handlers: ClientHandlers::default(), + } + } + + pub fn with_on_packet_recv(mut self, f: OnPacketRecvFn) -> Self { + self.handlers.on_packet_recv = f; + self + } + + pub fn with_handle_qos1_acknowledge(mut self, f: HandleQos1AcknowledgeFn) -> Self { + self.handlers.handle_qos1_acknowledge = f; + self + } + + pub async fn build(self) -> Result<super::MqttClient, MqttClientBuilderError> { + Ok({ + MqttClient { + inner: Arc::new(Mutex::new(InnerClient { + connection_state: None, + session_state: None, + default_handlers: self.handlers, + outstanding_callbacks: Callbacks::new(), + })), + } + }) + } +} + +#[derive(Debug, thiserror::Error)] +pub enum MqttClientBuilderError {} |