[][src]Crate mosquitto_rs

This crate implements an async MQTT client using libmosquitto.

use mosquitto_rs::*;

fn main() -> Result<(), Error> {
    smol::block_on(async {
        let mut client = Client::with_auto_id()?;
        let rc = client.connect(
                       "localhost", 1883,
                       std::time::Duration::from_secs(5), None).await?;
        println!("connect: {}", rc);

        let subscriptions = client.subscriber().unwrap();

        client.subscribe("test", QoS::AtMostOnce).await?;
        println!("subscribed");

        client.publish("test", b"woot", QoS::AtMostOnce, false)
            .await?;
        println!("published");

        if let Ok(msg) = subscriptions.recv().await {
            println!("msg: {:?}", msg);
        }

        Ok(())
    })
}

Structs

CallbackGuard
Client

A high-level, asynchronous mosquitto MQTT client

LibraryVersion

Represents the version of the linked mosquitto client library

Message

Represents a received message that matches one or more of the subscription topic patterns on a client.

Mosq

Mosq is the low-level mosquitto client. You probably want to look at Client instead.

Enums

Error
QoS

Traits

Callbacks

Defines handlers that can be used to determine when various functions have completed.

Functions

lib_version

Returns the version information for the linked mosquitto library

Type Definitions

MessageId

Represents an individual message identifier. This is used in this client to determine when a message has been sent.