Dbus: `msg` is a `&` reference, so the data it refers to cannot be borrowed as mutable


fn main() -> Result<(), std::io::Error> {
    // First open up a connection to the session bus.
    let mut conn = Connection::new_session().expect("D-Bus connection failed");

    // Second create a rule to match messages we want to receive; in this example we add no
    // further requirements, so all messages will match
    let mut rule = MatchRule::new();
    rule.path = Some("/org/freedesktop/Notifications".into());
    // rule.eavesdrop = true; // this lets us eavesdrop on *all* session messages, not just ours

    // Start matching
    conn.add_match(rule, |_: (), _, msg| {
        // how make msg as mut msg
        println!("{:?}", msg.as_result()); // error
    loop {

The Connection::add_match method does not provide mutable access to the Message, so there's no way for it to call Message::as_result.

Perhaps the dbus crate could add a new method that works like as_result but takes and returns a &Message instead of &mut Message. For now, I think you can use the read* methods instead, for example msg.read_all().

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.