blob: e8629eb31de8b627f3de21267ccd0df28e743e7d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 {}
|