gtk-rs / gtk-rs-core

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

`ObjectExt.emit_by_name()` has arcane syntax when there's no return value #1004

Open nirbheek opened 1 year ago

nirbheek commented 1 year ago

The documentation says:

fn emit_by_name<R: TryFromClosureReturnValue>(
    &self,
    signal_name: &str,
    args: &[&dyn ToValue]
) -> R

TryFromClosureReturnValue is completely unhelpful: https://gtk-rs.org/gtk-rs-core/stable/0.17/docs/glib/closure/trait.TryFromClosureReturnValue.html

It's really hard to figure out that you have to do obj.emit_by_name::<()>("signal-name", &[...]).

Maybe we can have emit_by_name() that discards the value and emit_by_name_return<R>() for when you want the return value?

pbor commented 1 year ago

I think the long term plan here is that we have a macro to generate signals that would also generate emit_foo with the right signature

sdroege commented 1 year ago

That doesn't help you with signals defined by GStreamer plugins, which I assume is what @nirbheek was using.

https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/252 would be somewhat a solution for that, but having a general nicer API would still be good.