pub struct Message { /* private fields */ }
Expand description
A Message
represents all the information passed in an MQTT PUBLISH
packet.
This is the primary data transfer mechanism.
Implementations
sourceimpl Message
impl Message
sourcepub fn new<S, V>(topic: S, payload: V, qos: i32) -> Self where
S: Into<String>,
V: Into<Vec<u8>>,
pub fn new<S, V>(topic: S, payload: V, qos: i32) -> Self where
S: Into<String>,
V: Into<Vec<u8>>,
Creates a new message.
Arguments
topic
The topic on which the message is published.payload
The binary payload of the messageqos
The quality of service for message delivery (0, 1, or 2)
sourcepub fn new_retained<S, V>(topic: S, payload: V, qos: i32) -> Self where
S: Into<String>,
V: Into<Vec<u8>>,
pub fn new_retained<S, V>(topic: S, payload: V, qos: i32) -> Self where
S: Into<String>,
V: Into<Vec<u8>>,
Creates a new message that will be retained by the broker. This creates a message with the ‘retained’ flag set.
Arguments
topic
The topic on which the message is published.payload
The binary payload of the messageqos
The quality of service for message delivery (0, 1, or 2)
sourcepub fn from_c_parts(topic: CString, cmsg: &MQTTAsync_message) -> Self
pub fn from_c_parts(topic: CString, cmsg: &MQTTAsync_message) -> Self
Creates a new message from C language components.
Arguments
topic
The topic on which the message is published.msg
The message struct from the C library
sourcepub fn payload(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn payload(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Gets the payload of the message. This returns the payload as a slice.
sourcepub 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.
sourcepub fn properties(&self) -> &Properties
pub fn properties(&self) -> &Properties
Gets the properties in the message
Trait Implementations
sourceimpl From<DeliveryToken> for Message
impl From<DeliveryToken> for Message
sourcefn from(v: DeliveryToken) -> Message
fn from(v: DeliveryToken) -> Message
Converts to this type from the input type.
sourceimpl From<Message> for WillOptions
impl From<Message> for WillOptions
impl Send for Message
impl Sync for Message
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more