ClientOptions

Struct ClientOptions 

pub struct ClientOptions {
    pub client_id: MqttString,
    pub keep_alive: u16,
    pub clean_start: bool,
    pub username: Option<MqttString>,
    pub password: Option<MqttBytesBuf>,
    pub session_expiry: Option<u32>,
    pub receive_maximum: Option<NonZeroU16>,
    pub topic_alias_maximum: Option<u16>,
    pub maximum_packet_size: Option<NonZeroU32>,
    pub will: Option<WillOptions>,
    pub reconnect: Option<ReconnectOptions>,
    pub journal_path: Option<PathBuf>,
}
Expand description

Options for the MQTT v5 client.

Controls the CONNECT packet fields, v5 session properties, and automatic reconnection behaviour.

Fields§

§client_id: MqttString

Client identifier. An empty string lets the broker assign one.

§keep_alive: u16

Keep-alive interval in seconds. 0 disables keep-alive.

§clean_start: bool

Whether to start a clean session.

§username: Option<MqttString>

Optional username for authentication.

§password: Option<MqttBytesBuf>

Optional password for authentication.

§session_expiry: Option<u32>

Session expiry interval in seconds (property 0x11). None = not sent; Some(0) = session ends on disconnect.

§receive_maximum: Option<NonZeroU16>

Maximum number of in-flight QoS 1/2 messages this client can handle (property 0x21).

§topic_alias_maximum: Option<u16>

Maximum topic alias value this client supports (property 0x22). None or Some(0) = topic aliases disabled.

§maximum_packet_size: Option<NonZeroU32>

Maximum packet size this client is willing to accept (property 0x27). None = no limit beyond protocol constraints.

§will: Option<WillOptions>

Will message configuration. None = no will message.

§reconnect: Option<ReconnectOptions>

Reconnect strategy. None disables automatic reconnection.

§journal_path: Option<PathBuf>

Path to a session journal file. When set, session state is persisted to this file so it can survive process restarts.

Implementations§

§

impl ClientOptions

pub const fn new(client_id: MqttString) -> Self

Create minimal options with a client ID.

Defaults: keep-alive 60 s, clean start, no auth, no reconnect.

pub const fn keep_alive(self, secs: u16) -> Self

Set the keep-alive interval in seconds.

pub const fn clean_start(self, clean: bool) -> Self

Set whether to start a clean session.

pub fn username(self, user: MqttString) -> Self

Set the username for authentication.

pub fn password(self, pass: MqttBytesBuf) -> Self

Set the password for authentication.

pub const fn session_expiry(self, seconds: u32) -> Self

Set the session expiry interval in seconds (v5 property 0x11).

pub const fn receive_maximum(self, max: NonZeroU16) -> Self

Set the receive maximum (v5 property 0x21).

pub const fn topic_alias_maximum(self, max: u16) -> Self

Set the topic alias maximum this client supports (v5 property 0x22).

pub const fn maximum_packet_size(self, max: NonZeroU32) -> Self

Set the maximum packet size this client will accept (v5 property 0x27).

pub fn will(self, topic: TopicBuf, payload: MqttBytesBuf) -> Self

Set a will message (Last Will and Testament).

The broker publishes this message if the client disconnects ungracefully.

pub fn will_with(self, will: WillOptions) -> Self

Set a will message with full configuration.

pub fn reconnect(self) -> Self

Enable automatic reconnection with default settings.

pub const fn reconnect_with(self, opts: ReconnectOptions) -> Self

Enable automatic reconnection with custom settings.

pub fn journal_path(self, path: impl Into<PathBuf>) -> Self

Set a session journal file path for durable session persistence.

fn iter_connect_properties(&self) -> impl Iterator<Item = Property<'_>>

pub(crate) fn to_connect_properties( &self, ) -> Result<ConnectPropertiesBuf, PropertiesBufError>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.