Struct MqttManager

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

The main MQTT manager struct

Implementations§

Source§

impl MqttManager

Source

pub fn new(host_url: &str) -> MqttManager

Create a new MqttManager from a host URL in the form:

  • mqtt://localhost:1883?client_id=client2
Source

pub async fn disconnect(&mut self)

Send a DISCONNECT to clean up the connection.

§panic

Panics when the call to disconnect fails.

Source

pub async fn publish<T, U>(&mut self, topic: T, payload: U, qos: u8)
where T: Into<String>, U: Into<Vec<u8>>,

Publish data to a topic.

topic is the topic name, payload is the payload bytes, and qos is the MQTT qos in the range 0-2

§panic

This panics if the qos is invalid or if there is an error publishing.

Source

pub async fn subscribe<T: Into<String>>( &mut self, topic: T, qos: u8, callback: CallbackFn, )

Subscribe to a topic.

topic is the subscription topic including optional wildcards per the MQTT spec. qos is the subscription qos in the range 0-3. callback is a callback async function which should be wrapped by calling crate::make_callback.

§panic

This panics if the qos is invalid or if there is an error subscribing.

Source

pub async fn process(&mut self) -> Result<(), ConnectionError>

Wait for a single packet and process reconnects, pings, etc.

This should be called reguarly, either in an event loop or in a background thread using tokio::spawn.

If a SUBSCRIBE packet is returned and there’s a registered callback it will be await’d.

Auto Trait Implementations§

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,