gtk-rs / gir

Tool to generate rust bindings and user API for glib-based libraries
https://gtk-rs.org/gir/book/
MIT License
230 stars 102 forks source link

Refactor `impl Default` generation #1446

Closed pbor closed 3 months ago

pbor commented 1 year ago

Move the detection of a default constructor function in the analysis. Move the logic about using Object::new into object.

pbor commented 1 year ago

I know a gir rework is ongoing, so I am not sure if refactoring PRs makes sense.

The reason for this is to tackle https://github.com/gtk-rs/gtk-rs-core/issues/975 by adding a new generate_default = false flag to Gir.toml, but before adding it I figured I would submit the refactoring

pbor commented 1 year ago

gtk3 fails because it has

impl Default for RadioButton {
    fn default() -> Self {
        Self::new()
    }
}

which is now generated... on the one hand I guess it is a good thing we can drop manual code, on the other it is not clear to me why this was not happening before :)

bilelmoussaoui commented 1 year ago

Would be nice to land this. But it needs PRs in at least 2 out of gtk-rs-core/gstreamer-rs/gtk4-rs with the resulting changes.

pbor commented 3 months ago

I looked at this again, and I do not think the PR is correct: the old code generated the fallback Object::new() constructor only if new was found (and was not hidden etc).

To make it correct we would have to remove the "0 args" check in the generic code, but that would defeat the point of centralizing this logic.