PublishBuilder

Struct PublishBuilder 

pub struct PublishBuilder<'a> {
    cmd_tx: &'a Sender<Command>,
    topic: TopicBuf,
    payload: Vec<u8>,
    qos: QoS,
    retain: bool,
    properties: PublishProperties,
}
Expand description

Builder for publishing a message with optional MQTT v5 properties.

Obtained via MqttClient::publish. Call send to enqueue the message (non-async, returns immediately) or send_async to wait for command queue space.

Fields§

§cmd_tx: &'a Sender<Command>§topic: TopicBuf§payload: Vec<u8>§qos: QoS§retain: bool§properties: PublishProperties

Implementations§

§

impl<'a> PublishBuilder<'a>

pub(crate) fn new( cmd_tx: &'a Sender<Command>, topic: TopicBuf, payload: Vec<u8>, ) -> Self

pub const fn qos(self, qos: QoS) -> Self

Set the Quality of Service level.

pub const fn retain(self, retain: bool) -> Self

Set the retain flag.

pub fn content_type(self, ct: MqttString) -> Self

Set the MIME content type (property 0x03).

pub fn response_topic(self, topic: TopicBuf) -> Self

Set the response topic for request/response flows (property 0x08).

pub fn correlation_data(self, data: MqttBytesBuf) -> Self

Set correlation data for request/response flows (property 0x09).

pub const fn message_expiry(self, seconds: u32) -> Self

Set the message expiry interval in seconds (property 0x02).

pub const fn payload_format(self, format: PayloadFormat) -> Self

Indicate whether the payload is UTF-8 encoded (property 0x01).

pub fn user_property(self, key: MqttString, value: MqttString) -> Self

Add a user property key-value pair (property 0x26). May be called multiple times.

pub fn send(self) -> Result<PublishToken, Error>

Enqueue the publish (non-blocking).

Returns a PublishToken that can be used to track progress and await the broker acknowledgement.

§Errors

Returns Error::ConnectionClosed if the internal command queue is full or the connection has been shut down.

pub async fn send_async(self) -> Result<PublishToken, Error>

Enqueue the publish, waiting for queue space if necessary.

Like send but applies back-pressure instead of failing when the queue is full.

§Errors

Returns Error::ConnectionClosed if the connection has been shut down.

Auto Trait Implementations§

§

impl<'a> Freeze for PublishBuilder<'a>

§

impl<'a> RefUnwindSafe for PublishBuilder<'a>

§

impl<'a> Send for PublishBuilder<'a>

§

impl<'a> Sync for PublishBuilder<'a>

§

impl<'a> Unpin for PublishBuilder<'a>

§

impl<'a> UnwindSafe for PublishBuilder<'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>,

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.