mosquitto-client-wrapper 0.2.0

Rust interface to the Mosquitto MQTT broker client. This is a fork of https://github.com/jsloth/mosquitto-client.
extern crate mosquitto_client_wrapper as mosq;
use mosq::Mosquitto;

use std::error::Error;

fn go() -> Result<(),Box<dyn Error>> {
    let m = Mosquitto::new("test")?;

    m.connect("localhost",1883,5)?;

    // publish and get a message id
    let our_mid = m.publish("bonzo/dog","hello dolly".as_bytes(), 2, false)?;

    // and wait for confirmation for that message id
    let mut mc = m.callbacks(());
    mc.on_publish(|_,mid| {
        if mid == our_mid {
            m.disconnect().unwrap();
        }
    });

    // wait forever until explicit disconnect
    m.loop_until_disconnect(-1)?;
    Ok(())
}

fn main() {
    go().expect("error: ");
}