pub struct MsgMatch(_);
Expand description
A struct used to handle incoming matches
Note: Due to the lack of async destructors, please call Connection.remove_match() in order to properly stop matching (instead of just dropping this struct).
Implementations
sourceimpl MsgMatch
impl MsgMatch
sourcepub fn msg_cb<F: FnMut(Message) -> bool + Send + 'static>(self, f: F) -> Self
pub fn msg_cb<F: FnMut(Message) -> bool + Send + 'static>(self, f: F) -> Self
Configures the match to receive a synchronous callback with only a message parameter.
sourcepub fn cb<R: ReadAll, F: FnMut(Message, R) -> bool + Send + 'static>(
self,
f: F
) -> Self
pub fn cb<R: ReadAll, F: FnMut(Message, R) -> bool + Send + 'static>(
self,
f: F
) -> Self
Configures the match to receive a synchronous callback with a message parameter and typed message arguments.
Example
let mr = MatchRule::new_signal("com.example.dbustest", "HelloHappened");
let incoming_signal = connection.add_match(mr).await?.cb(|_, (source,): (String,)| {
println!("Hello from {} happened on the bus!", source);
true
});
sourcepub fn msg_stream(self) -> (Self, UnboundedReceiver<Message>)
pub fn msg_stream(self) -> (Self, UnboundedReceiver<Message>)
Configures the match to receive a stream of messages.
Note: If the receiving end is disconnected and a message is received, the message matching will end but not in a clean fashion. Call remove_match() to stop matching cleanly.
sourcepub fn stream<R: ReadAll + Send + 'static>(
self
) -> (Self, UnboundedReceiver<(Message, R)>)
pub fn stream<R: ReadAll + Send + 'static>(
self
) -> (Self, UnboundedReceiver<(Message, R)>)
Configures the match to receive a stream of messages, parsed and ready.
Note: If the receiving end is disconnected and a message is received, the message matching will end but not in a clean fashion. Call remove_match() to stop matching cleanly.
Example
let mr = MatchRule::new_signal("com.example.dbustest", "HelloHappened");
let (incoming_signal, stream) = conn.add_match(mr).await?.stream();
let stream = stream.for_each(|(_, (source,)): (_, (String,))| {
println!("Hello from {} happened on the bus!", source);
async {}
});