pub struct CreateOptionsBuilder { /* private fields */ }
Expand description

Builder to construct client creation options.

Examples

use paho_mqtt as mqtt;

let opts = mqtt::CreateOptionsBuilder::new()
    .server_uri("tcp://localhost:1883")
    .client_id("client1")
    .finalize();

let cli = mqtt::AsyncClient::new(opts).unwrap();

Implementations§

source§

impl CreateOptionsBuilder

source

pub fn new() -> Self

Constructs a builder for a client that can connect using MQTT v3.x or v5.

source

pub fn new_v3() -> Self

Constructs a builder for a client that can only connect using MQTT v3.x.

source

pub fn server_uri<S>(self, server_uri: S) -> Selfwhere S: Into<String>,

Sets the the URI to the MQTT broker. Alternately, the application can specify multiple servers via the connect options.

Arguments

server_uri The URI string to specify the server in the form protocol://host:port, where the protocol can be tcp or ssl, and the host can be an IP address or domain name.

source

pub fn client_id<S>(self, client_id: S) -> Selfwhere S: Into<String>,

Sets the client identifier string that is sent to the server. The client ID is a unique name to identify the client to the server, which can be used if the client desires the server to hold state about the session. If the client requests a clean session, this can be an empty string, in which case the server will assign a random name for the client.

The broker is required to honor a client ID of up to 23 bytes, but could honor longer ones, depending on the broker.

Note that if this is an empty string, the clean session parameter must be set to true.

Arguments

client_id A UTF-8 string identifying the client to the server.

source

pub fn persistence<P>(self, persist: P) -> Selfwhere P: Into<PersistenceType>,

Sets the type of persistence used by the client. The default is for the library to automatically use file persistence, although this can be turned off by specify None for a more performant, though possibly less reliable system.

Arguments

persist The type of persistence to use.

source

pub fn user_persistence<T>(self, persistence: T) -> Selfwhere T: ClientPersistence + Send + 'static,

Sets a user-defined persistence store. This sets the persistence to use a custom one defined by the application. This can be anything that implements the ClientPersistence trait.

Arguments

persist An application-defined custom persistence store.

source

pub fn max_buffered_messages(self, n: i32) -> Self

Sets the maximum number of messages that can be buffered for delivery.

When the client is off-line, this specifies the maximum number of messages that can be buffered. Even while connected, the library needs a small buffer to queue outbound messages. Setting it to zero disables off-line buffering but still keeps some slots open for on-line operation.

Arguments

n The maximum number of messages that can be buffered. Setting this to zero also disables any off-line buffering.

source

pub fn send_while_disconnected(self, on: bool) -> Self

Allow the application to send (publish) messages while disconnected.

If this is disabled, then any time the app tries to publish while disconnected results in a “disconnected” error from the client. When enabled, the application can queue up to max_buffered_messages() while off-line.

Arguments

on Whether to allow off-line buffering in the client.

source

pub fn mqtt_version(self, ver: u32) -> Self

Sets the version of MQTT to use on the connect.

Arguments

ver The version of MQTT to use when connecting to the broker. * (0) try the latest version (3.1.1) and work backwards * (3) only try v3.1 * (4) only try v3.1.1 * (5) only try v5

source

pub fn allow_disconnected_send_at_anytime(self, allow: bool) -> Self

Allow sending of messages while disconnected before a first successful connect.

source

pub fn delete_oldest_messages(self, delete_oldest: bool) -> Self

When the maximum number of buffered messages is reached, delete the oldest rather than the newest.

source

pub fn restore_messages(self, restore: bool) -> Self

If set, messages from persistence are restored on create. Defaults to true.

source

pub fn persist_qos0(self, persist: bool) -> Self

If set, QoS0 publish commands are persisted. Defaults to true.

source

pub fn user_data(self, data: UserData) -> Self

Sets the user-defined data structure for the client.

source

pub fn finalize(self) -> CreateOptions

Constructs a set of create options from the builder information.

source

pub fn create_client(self) -> Result<AsyncClient>

Finalize the builder and create an asynchronous client.

Trait Implementations§

source§

impl Default for CreateOptionsBuilder

source§

fn default() -> CreateOptionsBuilder

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.