Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

An MQTT client.

Start building an instance by calling Client::builder() to get a ClientBuilder, using the fluent builder pattern on ClientBuilder, then calling ClientBuilder::build(). For example:

let client =
    Client::builder()
       .set_url_string("mqtt://example.com").unwrap()
       .build();

Client is expected to be Send (passable between threads), but not Sync (usable by multiple threads at the same time).

Implementations§

Source§

impl Client

Source

pub fn builder() -> ClientBuilder

Start a fluent builder interface to construct a Client.

Source

pub async fn connect(&mut self) -> Result<()>

Open a connection to the configured MQTT broker.

Source

pub async fn publish(&self, p: &Publish) -> Result<()>

Publish some data on a topic.

Note that this method takes &self. This means a caller can create several publish futures to publish several payloads of data simultaneously without waiting for responses.

Source

pub async fn subscribe(&mut self, s: Subscribe) -> Result<SubscribeResult>

Subscribe to some topics.read_subscriptions will return data for them.

Source

pub async fn unsubscribe(&mut self, u: Unsubscribe) -> Result<()>

Unsubscribe from some topics. read_subscriptions will no longer return data for them.

Source

pub async fn read_subscriptions(&mut self) -> Result<ReadResult>

Wait for the next Publish packet for one of this Client’s subscriptions.

Source

pub async fn disconnect(&mut self) -> Result<()>

Gracefully close the connection to the server.

Trait Implementations§

Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.