pub struct TopicMatcher<'a> {
pub mid: i32,
/* private fields */
}Expand description
Matching subscription topics. Returned from Mosquitto::subscribe.
Fields§
§mid: i32the subscription id.
Implementations§
Source§impl<'a> TopicMatcher<'a>
impl<'a> TopicMatcher<'a>
Sourcepub fn matches(&self, msg: &MosqMessage) -> bool
pub fn matches(&self, msg: &MosqMessage) -> bool
true if a message matches a subscription topic
Examples found in repository?
examples/subscribe-and-listen.rs (line 17)
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}Sourcepub fn receive_many(&self, millis: i32) -> Result<Vec<MosqMessage>>
pub fn receive_many(&self, millis: i32) -> Result<Vec<MosqMessage>>
receive and return messages matching this topic, until timeout
Examples found in repository?
examples/self-publish-receive-many.rs (line 20)
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 receive_one(&self, millis: i32) -> Result<MosqMessage>
pub fn receive_one(&self, millis: i32) -> Result<MosqMessage>
receive and return exactly one message matching this topic
Auto Trait Implementations§
impl<'a> Freeze for TopicMatcher<'a>
impl<'a> RefUnwindSafe for TopicMatcher<'a>
impl<'a> Send for TopicMatcher<'a>
impl<'a> Sync for TopicMatcher<'a>
impl<'a> Unpin for TopicMatcher<'a>
impl<'a> UnwindSafe for TopicMatcher<'a>
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