Struct paho_mqtt::topic::SyncTopic

source ·
pub struct SyncTopic<'a> { /* private fields */ }
Expand description

A topic destination for messages.

This keeps message parameters for repeatedly publishing to the same topic on a server.

Implementations§

source§

impl<'a> SyncTopic<'a>

source

pub fn new<T>(cli: &'a Client, topic: T, qos: i32) -> Self
where T: Into<String>,

Creates a new topic object for publishing messages.

§Arguments

cli The client used to publish the messages. topic The topic on which to publish the messages qos The quality of service for messages

source

pub fn new_retained<T>(cli: &'a Client, topic: T, qos: i32) -> Self
where T: Into<String>,

Creates a new topic object for publishing messages.

§Arguments

cli The client used to publish the messages. topic The topic on which to publish the messages qos The quality of service for messages

source

pub fn create_message<V>(&self, payload: V) -> Message
where V: Into<Vec<u8>>,

Create a message for the topic using the supplied payload

source

pub fn subscribe(&self) -> Result<ServerResponse>

Subscribe to the topic.

source

pub fn subscribe_with_options<T, P>( &self, opts: T, props: P ) -> Result<ServerResponse>

Subscribe to the topic with subscription options.

source

pub fn publish<V>(&self, payload: V) -> Result<()>
where V: Into<Vec<u8>>,

Publish a message on the topic.

If a topic alias was previously sent, this will use the integer alias property instead of sending the topic string. Topic aliases are only applicable for MQTT v5 connections.

§Arguments

payload The payload of the message

source

pub fn publish_with_alias<V>(&mut self, alias: u16, payload: V) -> Result<()>
where V: Into<Vec<u8>>,

Publish a message with a topic alias.

This publishes the message with a topic alias property to set the alias at the broker. After calling this, the object keeps the alias and uses it for subsequent publishes instead of sending the full topic string.

Note that using an alias is only valid with an MQTT v5 connection, and the value must be in the range of 1 - TopicAliasMaximum as the broker reported in the CONNACK packet. The alias is only valid for a single connection. It should be reset on a reconnect.

This can be called a second time to change the alias setting. Using an alias of zero on a subsequent call instructs this object to stop using the alias and publish with the topic name.

§Arguments

alias The integer alias to use for subsequent message publishing. This must be in the range 1 - TopicAliasMaximum as reported by the server in the CONNACK package. Using a value of zero instructs this object to stop using the alias and go back to publishing with the string topic name. payload The payload of the message

source

pub fn alias(&self) -> Option<u16>

Gets the alias for the topic, if any.

source

pub fn remove_alias(&mut self)

Removes the alias, if any, from the topic.

After removing the alias, publshed messages contain the full string topic. The alias mapping remains on the server though. The alias number cann be reused by assigning to a different topic, but the only way to remove it is to disconnect the client.

Auto Trait Implementations§

§

impl<'a> Freeze for SyncTopic<'a>

§

impl<'a> !RefUnwindSafe for SyncTopic<'a>

§

impl<'a> Send for SyncTopic<'a>

§

impl<'a> Sync for SyncTopic<'a>

§

impl<'a> Unpin for SyncTopic<'a>

§

impl<'a> !UnwindSafe for SyncTopic<'a>

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.