MqttClientBuilder

Struct MqttClientBuilder 

pub struct MqttClientBuilder<'a> {
    pub(crate) certificate: Option<&'a [u8]>,
    pub(crate) private_key: Option<&'a [u8]>,
    pub(crate) certificate_authority: Option<&'a [u8]>,
    pub(crate) thing_name: Option<&'a str>,
    pub(crate) endpoint: Option<Cow<'a, str>>,
    pub(crate) keep_alive: Option<Duration>,
    pub(crate) min_reconnect_delay: Option<Duration>,
    pub(crate) max_reconnect_delay: Option<Duration>,
    pub(crate) connect_timeout: Option<Duration>,
    pub(crate) subscriber_capacity: usize,
    pub(crate) port: Option<u16>,
}
Expand description

A builder for creating an MqttClient with specific configurations.

Fields§

§certificate: Option<&'a [u8]>§private_key: Option<&'a [u8]>§certificate_authority: Option<&'a [u8]>§thing_name: Option<&'a str>§endpoint: Option<Cow<'a, str>>§keep_alive: Option<Duration>§min_reconnect_delay: Option<Duration>§max_reconnect_delay: Option<Duration>§connect_timeout: Option<Duration>§subscriber_capacity: usize§port: Option<u16>

Implementations§

§

impl<'a> MqttClientBuilder<'a>

pub const fn new() -> Self

Creates a new MqttClientBuilder with default settings.

§Returns

A new MqttClientBuilder instance.

pub const fn thing_name(self, name: &'a str) -> Self

Sets the name of the thing

pub fn endpoint(self, endpoint: &'a str) -> Self

Sets the MQTT endpoint to connect to.

See also endpoint_owned.

pub fn endpoint_owned(self, endpoint: String) -> Self

Sets the MQTT endpoint to connect to.

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

Sets the MQTT port to connect to.

pub const fn certificate(self, cert: &'a [u8]) -> Self

Sets the certificate to use for the MQTT connection.

pub const fn private_key(self, key: &'a [u8]) -> Self

Sets the private key to use for the MQTT connection.

pub const fn ca(self, ca: &'a [u8]) -> Self

Sets the certificate authority to use for the MQTT connection.

pub const fn keep_alive(self, time: Duration) -> Self

Set number of seconds after which client should ping the broker if there is no other data exchange

pub const fn connect_timeout(self, time: Duration) -> Self

Sets the connect timeout.

This timeout is used when connecting to the broker. The value only has a resolution of seconds.

Any value less than 1 second will be treated as 0 seconds, which will cause the connection to fail instantly.

Defaults to 5 seconds.

pub const fn min_reconnect_delay(self, time: Duration) -> Self

Sets the minimum delay between reconnection attempts.

If set to Duration::ZERO, the client will always attempt to reconnect immediately without delay, effectively disabling backoff. This is not recommended for production use.

Defaults to 1 second.

pub const fn max_reconnect_delay(self, time: Duration) -> Self

Sets the maximum delay between reconnection attempts.

If set to a value less than the minimum reconnect delay, the minimum reconnect delay will be used instead.

Defaults to 5 minutes.

pub const fn subscriber_capacity(self, size: usize) -> Self

Sets the maximum capacity for a Subscriber receiver channel. This allows controlling the buffer size for incoming messages to subscribers. A larger buffer can prevent message loss, but may consume more memory.

pub fn build(self) -> Result<MqttClient>

Trait Implementations§

§

impl<'a> Debug for MqttClientBuilder<'a>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl<'a> Default for MqttClientBuilder<'a>

§

fn default() -> MqttClientBuilder<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MqttClientBuilder<'a>

§

impl<'a> RefUnwindSafe for MqttClientBuilder<'a>

§

impl<'a> Send for MqttClientBuilder<'a>

§

impl<'a> Sync for MqttClientBuilder<'a>

§

impl<'a> Unpin for MqttClientBuilder<'a>

§

impl<'a> UnwindSafe for MqttClientBuilder<'a>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more