Struct minimq::publication::Publication
source · pub struct Publication<'a, P: ToPayload> { /* private fields */ }
Expand description
Builder pattern for generating MQTT publications.
§Note
By default, messages are constructed with:
- A QoS setting of QoS::AtMostOnce
- No properties
- No destination topic
- Retention set to Retain::NotRetained
It is expected that the user provide a topic either by directly specifying a publication topic in Publication::topic, or by parsing a topic from the Property::ResponseTopic property contained within received properties by using the Publication::reply API.
Implementations§
source§impl<'a, P: ToPayload> Publication<'a, P>
impl<'a, P: ToPayload> Publication<'a, P>
sourcepub fn qos(self, qos: QoS) -> Self
pub fn qos(self, qos: QoS) -> Self
Specify the QoS of the publication. By default, the QoS is set to QoS::AtMostOnce.
sourcepub fn retain(self) -> Self
pub fn retain(self) -> Self
Specify that this message should be Retain::Retained.
sourcepub fn topic(self, topic: &'a str) -> Self
pub fn topic(self, topic: &'a str) -> Self
Specify the publication topic for this message.
§Note
If this is called after Publication::reply determines a response topic, the response topic will be overridden.
sourcepub fn properties(self, properties: &'a [Property<'a>]) -> Self
pub fn properties(self, properties: &'a [Property<'a>]) -> Self
Specify properties associated with this publication.
sourcepub fn reply(self, received_properties: &'a Properties<'a>) -> Self
pub fn reply(self, received_properties: &'a Properties<'a>) -> Self
Generate the publication as a reply to some other received message.
§Note
The received message properties are parsed for both Property::CorrelationData and Property::ResponseTopic.
-
If correlation data is found, it is automatically appended to the publication properties.
-
If a response topic is identified, the message topic will be configured for it, which will override any previously-specified topic.
sourcepub fn finish(self) -> Result<Pub<'a, P>, ProtocolError>
pub fn finish(self) -> Result<Pub<'a, P>, ProtocolError>
Generate the final publication.
§Returns
The message to be published if a publication topic was specified. If no publication topic was identified, an error is returned.