rust_mqtt/client/options/
connect.rs1use core::num::NonZero;
2
3use const_fn::const_fn;
4
5use crate::{
6 client::options::WillOptions,
7 config::{KeepAlive, MaximumPacketSize, SessionExpiryInterval},
8 types::{MqttBinary, MqttString},
9};
10
11#[derive(Debug, Clone)]
13#[cfg_attr(feature = "defmt", derive(defmt::Format))]
14pub struct Options<'c> {
15 pub clean_start: bool,
17
18 pub keep_alive: KeepAlive,
20
21 pub session_expiry_interval: SessionExpiryInterval,
23
24 pub maximum_packet_size: MaximumPacketSize,
26
27 pub request_response_information: bool,
29
30 pub user_name: Option<MqttString<'c>>,
32 pub password: Option<MqttBinary<'c>>,
34
35 pub will: Option<WillOptions<'c>>,
37}
38
39impl Default for Options<'_> {
40 fn default() -> Self {
41 Self::new()
42 }
43}
44
45impl<'c> Options<'c> {
46 #[must_use]
49 pub const fn new() -> Self {
50 Self {
51 clean_start: false,
52 keep_alive: KeepAlive::Infinite,
53 session_expiry_interval: SessionExpiryInterval::EndOnDisconnect,
54 maximum_packet_size: MaximumPacketSize::Unlimited,
55 request_response_information: false,
56 user_name: None,
57 password: None,
58 will: None,
59 }
60 }
61
62 #[must_use]
64 pub const fn clean_start(mut self) -> Self {
65 self.clean_start = true;
66 self
67 }
68 #[must_use]
70 pub const fn keep_alive(mut self, keep_alive: KeepAlive) -> Self {
71 self.keep_alive = keep_alive;
72 self
73 }
74 #[must_use]
76 pub const fn session_expiry_interval(mut self, interval: SessionExpiryInterval) -> Self {
77 self.session_expiry_interval = interval;
78 self
79 }
80 #[must_use]
82 pub const fn maximum_packet_size(mut self, maximum_packet_size: NonZero<u32>) -> Self {
83 self.maximum_packet_size = MaximumPacketSize::Limit(maximum_packet_size);
84 self
85 }
86 #[must_use]
89 pub const fn request_response_information(mut self) -> Self {
90 self.request_response_information = true;
91 self
92 }
93 #[const_fn(cfg(not(feature = "alloc")))]
95 #[must_use]
96 pub const fn user_name(mut self, user_name: MqttString<'c>) -> Self {
97 self.user_name = Some(user_name);
98 self
99 }
100 #[const_fn(cfg(not(feature = "alloc")))]
102 #[must_use]
103 pub const fn password(mut self, password: MqttBinary<'c>) -> Self {
104 self.password = Some(password);
105 self
106 }
107 #[const_fn(cfg(not(feature = "alloc")))]
109 #[must_use]
110 pub const fn will(mut self, will: WillOptions<'c>) -> Self {
111 self.will = Some(will);
112 self
113 }
114}