gtk-rs-core icon indicating copy to clipboard operation
gtk-rs-core copied to clipboard

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

Open nirbheek opened this issue 2 years ago • 2 comments

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?

nirbheek avatar Feb 16 '23 13:02 nirbheek

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

pbor avatar Feb 18 '23 09:02 pbor

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.

sdroege avatar Feb 18 '23 09:02 sdroege