Struct minimq::mqtt_client::Minimq

source ·
pub struct Minimq<'buf, TcpStack, Clock, Broker>
where TcpStack: TcpClientStack, Clock: Clock, Broker: Broker,
{ /* private fields */ }
Expand description

The general structure for managing MQTT via Minimq.

Note

To connect and maintain an MQTT connection, the Minimq::poll() method must be called regularly.

Implementations§

source§

impl<'buf, TcpStack: TcpClientStack, Clock: Clock, Broker: Broker> Minimq<'buf, TcpStack, Clock, Broker>

source

pub fn new( network_stack: TcpStack, clock: Clock, config: ConfigBuilder<'buf, Broker> ) -> Self

Construct a new MQTT interface.

Args
  • broker - The broker to connect to. See crate::broker::NamedBroker and crate::broker::IpBroker.
  • client_id The client ID to use for communicating with the broker. If empty, rely on the broker to automatically assign a client ID.
  • network_stack - The network stack to use for communication.
  • clock - The clock to use for managing MQTT state timing.
Returns

A Minimq object that can be used for publishing messages, subscribing to topics, and managing the MQTT state.

source

pub fn poll<F, T>(&mut self, f: F) -> Result<Option<T>, Error<TcpStack::Error>>
where for<'a> F: FnMut(&mut MqttClient<'buf, TcpStack, Clock, Broker>, &'a str, &[u8], &Properties<'a>) -> T,

Check the MQTT interface for available messages.

Note

This method will processes as many MQTT control packets as possible until a PUBLISH message is received. The user should thus contintually call this function until it returns Ok(None), as this is indicative that there is no further data to process.

Args
  • f - A closure to process any received messages. The closure should accept the client, topic, message, and list of proprties (in that order).
Returns

Ok(Option) - During normal operation, a will optionally be returned to the user software if a value was returned from the f closure. If the closure was not executed, None is returned. Note that None may be returned even if MQTT packets were processed.

Err(Error) if an MQTT-related error is encountered. Generally, Error::SessionReset is the only error expected during normal operation. In this case, the client has lost any previous subscriptions or session state.

source

pub fn client(&mut self) -> &mut MqttClient<'buf, TcpStack, Clock, Broker>

Directly access the MQTT client.

Auto Trait Implementations§

§

impl<'buf, TcpStack, Clock, Broker> RefUnwindSafe for Minimq<'buf, TcpStack, Clock, Broker>
where Broker: RefUnwindSafe, Clock: RefUnwindSafe, TcpStack: RefUnwindSafe, <Clock as Clock>::T: RefUnwindSafe, <TcpStack as TcpClientStack>::TcpSocket: RefUnwindSafe,

§

impl<'buf, TcpStack, Clock, Broker> Send for Minimq<'buf, TcpStack, Clock, Broker>
where Broker: Send, Clock: Send, TcpStack: Send, <Clock as Clock>::T: Send, <TcpStack as TcpClientStack>::TcpSocket: Send,

§

impl<'buf, TcpStack, Clock, Broker> Sync for Minimq<'buf, TcpStack, Clock, Broker>
where Broker: Sync, Clock: Sync, TcpStack: Sync, <Clock as Clock>::T: Sync, <TcpStack as TcpClientStack>::TcpSocket: Sync,

§

impl<'buf, TcpStack, Clock, Broker> Unpin for Minimq<'buf, TcpStack, Clock, Broker>
where Broker: Unpin, Clock: Unpin, TcpStack: Unpin, <Clock as Clock>::T: Unpin, <TcpStack as TcpClientStack>::TcpSocket: Unpin,

§

impl<'buf, TcpStack, Clock, Broker> !UnwindSafe for Minimq<'buf, TcpStack, Clock, Broker>

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>,

§

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>,

§

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.