pub struct Message {
pub topic: String,
pub payload: Vec<u8>,
}Expand description
A message that arrived on a subscribed topic.
Every link that can deliver hands back the same shape, so a node reads a command the same way whether it came over MQTT, CoAP, Zenoh, or the in-process broker used in tests.
Fields§
§topic: StringThe topic the message was published to.
payload: Vec<u8>The raw payload bytes.
Implementations§
Source§impl Message
impl Message
Sourcepub fn text(&self) -> Result<&str>
pub fn text(&self) -> Result<&str>
Reads the payload as text.
Most readings and commands on a topic are words or a number written out, and this is the accessor for them; a payload that is a codec’s bytes goes through the codec instead.
§Returns
The payload as a string slice.
§Errors
Returns Error::Codec if the payload is not UTF-8 text.
Trait Implementations§
impl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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
Mutably borrows from an owned value. Read more