Struct PublishBuilder
pub struct PublishBuilder {
cmd_tx: Sender<Command>,
topic: TopicBuf,
payload: Vec<u8>,
qos: QoS,
retain: bool,
properties: PublishOptions,
}Expand description
Builder for publishing a message with optional MQTT v5 properties.
Obtained via MqttClient::publish.
Call send to obtain a PublishFuture. The future is
lazy: no work is done until it is polled.
Fields§
§cmd_tx: Sender<Command>§topic: TopicBuf§payload: Vec<u8>§qos: QoS§retain: bool§properties: PublishOptionsImplementations§
Source§impl PublishBuilder
impl PublishBuilder
Sourcepub const fn retain(self, retain: bool) -> PublishBuilder
pub const fn retain(self, retain: bool) -> PublishBuilder
Sets the retain flag.
Sourcepub fn content_type(self, ct: MqttString) -> PublishBuilder
pub fn content_type(self, ct: MqttString) -> PublishBuilder
Sets the MIME content type (property 0x03).
Sourcepub fn response_topic(self, topic: TopicBuf) -> PublishBuilder
pub fn response_topic(self, topic: TopicBuf) -> PublishBuilder
Sets the response topic for request/response flows (property 0x08).
Sourcepub fn correlation_data(self, data: MqttBytesBuf) -> PublishBuilder
pub fn correlation_data(self, data: MqttBytesBuf) -> PublishBuilder
Sets correlation data for request/response flows (property 0x09).
Sourcepub const fn message_expiry(self, seconds: u32) -> PublishBuilder
pub const fn message_expiry(self, seconds: u32) -> PublishBuilder
Sets the message expiry interval in seconds (property 0x02).
Sourcepub const fn payload_format(self, format: PayloadFormat) -> PublishBuilder
pub const fn payload_format(self, format: PayloadFormat) -> PublishBuilder
Indicate whether the payload is UTF-8 encoded (property 0x01).
Sourcepub fn user_property(self, key: MqttString, value: MqttString) -> PublishBuilder
pub fn user_property(self, key: MqttString, value: MqttString) -> PublishBuilder
Adds a user property key-value pair (property 0x26).
May be called multiple times.
Sourcepub fn send(self) -> PublishFuture ⓘ
pub fn send(self) -> PublishFuture ⓘ
Returns a lazy future representing the publish.
No work is done until the future is polled. Awaiting it drives the
publish to broker acknowledgement (PUBACK for QoS 1, PUBCOMP for
QoS 2). For QoS 0 it resolves once the bytes have been written.
Call PublishFuture::queued on the returned future if you only need
to wait for the message to be persisted locally.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PublishBuilder
impl RefUnwindSafe for PublishBuilder
impl Send for PublishBuilder
impl Sync for PublishBuilder
impl Unpin for PublishBuilder
impl UnsafeUnpin for PublishBuilder
impl UnwindSafe for PublishBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more