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
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Start a fluent builder interface to construct a Client
.
Sourcepub async fn publish(&self, p: &Publish) -> Result<()>
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.
Sourcepub async fn subscribe(&mut self, s: Subscribe) -> Result<SubscribeResult>
pub async fn subscribe(&mut self, s: Subscribe) -> Result<SubscribeResult>
Subscribe to some topics.read_subscriptions
will return
data for them.
Sourcepub async fn unsubscribe(&mut self, u: Unsubscribe) -> Result<()>
pub async fn unsubscribe(&mut self, u: Unsubscribe) -> Result<()>
Unsubscribe from some topics. read_subscriptions
will no
longer return data for them.
Sourcepub async fn read_subscriptions(&mut self) -> Result<ReadResult>
pub async fn read_subscriptions(&mut self) -> Result<ReadResult>
Wait for the next Publish packet for one of this Client’s subscriptions.
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Gracefully close the connection to the server.