dbus2 / zbus

Rust D-Bus crate.
Other
316 stars 70 forks source link

Connection doesn't appear to implement Sync #869

Closed skewballfox closed 1 week ago

skewballfox commented 1 week ago

Sorry if this is a red herring, but I'm attempting to call connection::session within a closure that is expected to return a future that is both send and sync. I get a series of errors indicating that Connection does not (I suppose cannot auto) implement sync.

here's a stripped down version of the method that reproduces the issue

.with_on_start(move |_, _, _| {
    async move {
                let connection = Connection::session().await?;
        }
})

where with_on_start takes functions with the following signature

Box<dyn Fn(ProcessManager, ProcessKey, bool) -> ReturnFuture + Send + Sync + 'static>;

I'm attaching the full compiler diagnostics if it helps diagnostics.txt

zeenix commented 1 week ago

Connection does not (I suppose cannot auto) implement sync.

It most certainly does. I went through a lot of trouble and had to make some tough decisions to make that happen. We even check for it as part of the every build. :)

Your issue is the future returned by Connection::session. I don't have sufficient context to help you better but since Connection is Send+Sync and cheaply clonable, typically the best thing to do, is to create the connection once and then pass it (or its clones) around wherever needed in the code.

If that's not an option, I'd suggest to try pinning on the heap using Box::pin(Connection::session()). It may or may not help.

I hope that helps. I'm not sure what zbus can do to help but if you've specific ideas, please do let us know and I'll see what I can do (starting with reopenning this issue :smile:).