Struct Message
pub struct Message {
pub(crate) cmsg: MQTTAsync_message,
pub(crate) data: Pin<Box<MessageData>>,
}Expand description
A Message represents all the information passed in an MQTT PUBLISH
packet.
This is the primary data transfer mechanism.
Fields§
§cmsg: MQTTAsync_message§data: Pin<Box<MessageData>>Implementations§
§impl Message
impl Message
pub fn new<S, V, Q>(topic: S, payload: V, qos: Q) -> Message
pub fn new<S, V, Q>(topic: S, payload: V, qos: Q) -> Message
Creates a new message.
§Arguments
topicThe topic on which the message is published.payloadThe binary payload of the messageqosThe quality of service for message delivery (0, 1, or 2)
pub fn new_retained<S, V, Q>(topic: S, payload: V, qos: Q) -> Message
pub fn new_retained<S, V, Q>(topic: S, payload: V, qos: Q) -> Message
Creates a new message that will be retained by the broker. This creates a message with the ‘retained’ flag set.
§Arguments
topicThe topic on which the message is published.payloadThe binary payload of the messageqosThe quality of service for message delivery (0, 1, or 2)
pub fn payload(&self) -> &[u8] ⓘ
pub fn payload(&self) -> &[u8] ⓘ
Gets the payload of the message. This returns the payload as a slice.
pub fn payload_str(&self) -> Cow<'_, str>
pub fn payload_str(&self) -> Cow<'_, str>
Gets the payload of the message as a string.
This utilizes the “lossy” style of conversion from the std library.
If the contents of the CStr are valid UTF-8 data, this function will
return a Cow::Borrowed(&str) with the the corresponding &str slice.
Otherwise, it will replace any invalid UTF-8 sequences with U+FFFD
REPLACEMENT CHARACTER and return a Cow::Owned(String) with the result.
pub fn qos(&self) -> QoS
pub fn qos(&self) -> QoS
Returns the Quality of Service (QOS) for the message.
pub fn properties(&self) -> &Properties
pub fn properties(&self) -> &Properties
Gets the properties in the message