pub struct MosqMessage { /* private fields */ }Expand description
A mosquitto message
Implementations§
Source§impl MosqMessage
impl MosqMessage
Sourcepub fn topic(&self) -> &str
pub fn topic(&self) -> &str
the topic of the message. This will panic if the topic isn’t valid UTF-8
Examples found in repository?
examples/self-publish-receive-many.rs (line 22)
5fn run() -> mosq::Result<()> {
6 let m = Mosquitto::new("test");
7
8 m.connect_wait("localhost",1883,300)?;
9 let bilbo = m.subscribe("bilbo/#",1)?;
10
11 let mt = m.clone();
12 thread::spawn(move || {
13 for i in 0..5 {
14 let topic = format!("bilbo/{}",10*(i+1));
15 let data = format!("hello #{}",i);
16 mt.publish(&topic,data.as_bytes(), 1, false).unwrap();
17 }
18 });
19
20 let msgs = bilbo.receive_many(300)?;
21 for msg in msgs {
22 println!("topic {} text '{}'",msg.topic(),msg.text());
23 }
24 Ok(())
25}Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
the payload as text. This will panic if the payload was not valid UTF-8
Examples found in repository?
examples/self-publish-receive-many.rs (line 22)
5fn run() -> mosq::Result<()> {
6 let m = Mosquitto::new("test");
7
8 m.connect_wait("localhost",1883,300)?;
9 let bilbo = m.subscribe("bilbo/#",1)?;
10
11 let mt = m.clone();
12 thread::spawn(move || {
13 for i in 0..5 {
14 let topic = format!("bilbo/{}",10*(i+1));
15 let data = format!("hello #{}",i);
16 mt.publish(&topic,data.as_bytes(), 1, false).unwrap();
17 }
18 });
19
20 let msgs = bilbo.receive_many(300)?;
21 for msg in msgs {
22 println!("topic {} text '{}'",msg.topic(),msg.text());
23 }
24 Ok(())
25}Sourcepub fn qos(&self) -> u32
pub fn qos(&self) -> u32
the quality-of-service of the message. The desired QoS is specified when we subscribe.
Sourcepub fn retained(&self) -> bool
pub fn retained(&self) -> bool
was the message retained by the broker? True if we received this as a retained message. Subsequent messages marked as retained will not set this.
Examples found in repository?
examples/subscribe-and-listen.rs (line 16)
4fn main() {
5 let m = Mosquitto::new("test");
6
7 m.will_set("test/will",b"finished!",0,false).expect("can't set will");
8
9 m.connect("localhost",1883).expect("can't connect");
10 let bonzo = m.subscribe("bonzo/#",0).expect("can't subscribe to bonzo");
11 let frodo = m.subscribe("frodo/#",0).expect("can't subscribe to frodo");
12
13 // not interested in any retained messages!
14 let mut mc = m.callbacks(());
15 mc.on_message(|_,msg| {
16 if ! msg.retained() {
17 if bonzo.matches(&msg) {
18 println!("bonzo {:?}",msg);
19 } else
20 if frodo.matches(&msg) {
21 println!("frodo {:?}",msg);
22 m.disconnect().unwrap();
23 }
24 }
25 });
26
27 m.loop_forever(200).expect("broken loop");
28}Trait Implementations§
Source§impl Clone for MosqMessage
impl Clone for MosqMessage
Source§impl Debug for MosqMessage
impl Debug for MosqMessage
Auto Trait Implementations§
impl Freeze for MosqMessage
impl RefUnwindSafe for MosqMessage
impl !Send for MosqMessage
impl !Sync for MosqMessage
impl Unpin for MosqMessage
impl UnwindSafe for MosqMessage
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