gtk-rs / gtk-rs-core

Rust bindings for GNOME libraries
https://gtk-rs.org/gtk-rs-core
MIT License
279 stars 110 forks source link

gio: `DBusConnection::register_object` should support `NULL` callbacks #258

Open ids1024 opened 3 years ago

ids1024 commented 3 years ago

https://docs.gtk.org/gio/method.DBusConnection.register_object_with_closures.html documents these arguments as nullable, and https://docs.gtk.org/gio/struct.DBusInterfaceVTable.html mentions:

Since 2.38, if you want to handle getting/setting D-Bus properties asynchronously, give NULL as your get_property() or set_property() function. The D-Bus call will be directed to your method_call function, with the provided interface_name set to “org.freedesktop.DBus.Properties”.

So presumably this function should be usable with None for get_property/set_property to be able to cover this use case.

Given None isn't practical for generic function types, changing the function to use the builder pattern would probably make sense.

sdroege commented 3 years ago

You could also go with Option<Box<dyn Fn(...) -> ...>> for starters but that's less nice to use of course.

ids1024 commented 3 years ago

that's less nice to use of course

And inconsistent with other gtk-rs APIs.

I wish the never type was available and implemented function traits so None::<!> could magically work (maybe it will at some point). But a builder pattern probably looks cleaner when passing multiple closures anyway.