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:

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>

source

pub fn new(payload: P) -> Self

Construct a new publication with a payload.

source

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

Specify the QoS of the publication. By default, the QoS is set to QoS::AtMostOnce.

source

pub fn retain(self) -> Self

Specify that this message should be Retain::Retained.

source

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.

source

pub fn properties(self, properties: &'a [Property<'a>]) -> Self

Specify properties associated with this publication.

source

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.

source

pub fn correlate(self, data: &'a [u8]) -> Self

Include correlation data to the message

§Note

This will override any existing correlation data in the message.

§Args
  • data - The data composing the correlation data.
source

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.

Auto Trait Implementations§

§

impl<'a, P> Freeze for Publication<'a, P>
where P: Freeze,

§

impl<'a, P> RefUnwindSafe for Publication<'a, P>
where P: RefUnwindSafe,

§

impl<'a, P> Send for Publication<'a, P>
where P: Send,

§

impl<'a, P> Sync for Publication<'a, P>
where P: Sync,

§

impl<'a, P> Unpin for Publication<'a, P>
where P: Unpin,

§

impl<'a, P> UnwindSafe for Publication<'a, P>
where P: UnwindSafe,

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.