Hi,

I've started playing with Rust bindings to GObject:
https://github.com/mzabaluev/grust

The intent is to make any API that provides a GObject introspection safely
usable in Rust. There are two important things about GLib objects:
1. The objects are reference counted in a thread-safe way.
2. The objects in general are not thread-safe: threads calling methods on
one object need to be synchronized.

In my proof-of-concept code, the Rust safe wrappers for the objects are
intended to be cloneable and sendable by virtue of the GLib refcounting.
But this may mean that an object may end up being used concurrently from
multiple tasks. Are there any best practices for wrapping such objects? One
solution I see is to dispatch all GObject calls through a dedicated
ever-running task initialized on program startup (GObject needs an explicit
init call anyway, so it's no big deal to add), but this grand central
approach may not be optimal or flexible enough.

Another topic of interest is casting. GObject provides runtime type
information and supports dynamic type checks. This means we can safely
down- and side-cast between traits representing GObject classes or
interfaces, but we need a custom cast implementation. Is there any
idiomatic trait to reuse?

Best regards,
  Mikhail
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to