gnome-class and gobject-subclass



Hi everybody,

I heard that there were some misconceptions about my work on gobject-
subclass[0] and how it relates to the gnome-class[1] work of Federico.

Let's clear that up!


First of all, gobject-subclass is not meant as an alternative to gnome-
class or even a competitor. It's meant to be a building block that
gnome-class can make use of in the future to generate less code, and
especially less unsafe code, and more important to have a lot of glue
code already included in the bindings instead of generating it over and
over again for each class (but more on that at the very end). My view
on the situation right now is that Federico and I are working towards
the same goal from a different starting point and hopefully meet at the
middle at some point to make use of what the other already built.


So what is gobject-subclass exactly? It's a set of traits that allow to
implement GObject subclasses from pure, safe Rust with all its features
and without macros. It builds upon the existing gtk-rs bindings and
adds various pieces to it for subclassing, like for example the virtual
method trampolines, i.e. the conversion between C types, Rust types and
back for the virtual methods and the ability to call a parent class'
implementation of a virtual method.
For that there is a PR[2] (not by me but by a great contributor) for
the gir code generator to autogenerate as much as possible for all of
this, but to still allow for manual implementations of pieces as is
necessary.

It comes from my experiments for writing GStreamer plugins[3] in Rust
(which went from experiment to used-in-production already), and there's
also a (rather empty so far) companion for being able to write
subclasses of GTK types[4].

A simple example object making use of basically all features can be
found here[5], a more realistic example for a GListModel item used in a
GtkBox can be found here[6] and another example creating a subclass of
GApplication here[7].


My goal is to provide something in the end that gnome-subclass can use
to generate less code, less unsafe code and make use of library crate
code instead of regenerating everything for every object and thus
generally improve debuggability and reduce complexity. And as a side-
effect having a solution that already works nowadays on stable Rust and
in the future continues to work without a macro-based DSL (which I know
many people dislike) at the cost of writing more code, while still
building upon the same foundation as everything else.

Basically gnome-class could generate code like the manually written one
above. I'm sure there are still some missing features and
impedance mismatch (I know of some things), but that's all solveable
and we'll probably notice that once someone tries the integration. IMHO
at this point, gobject-subclass has reached a point where integration
can be tried and this is also why I didn't bring that forward before.
To allow Federico to focus on gnome-class without having yet another
construction area.



And independent of all the advantages above, I also believe that gnome-
class will actually need this. While it is possible to autogenerate
most bindings code, there are always exceptions. And this exception is
not only GStreamer in many places, but even in gio and gtk already, for
example in the argument handling of GApplication[8] or the lifetimes of
items in GActionMap (solution still to be found[9]).

One could possibly implement a system for gnome-class to take care of
that automatically, and to require overrides/manual implementations to
be stored somewhere for gnome-class to find them, but it seems
suboptimal. The gtk-rs bindings are exactly the place where such
special handling is already implemented once for the "consumer-side" of
the bindings, it should be possible to put the same in there for the
"producer-side" (subclassing).


Sebastian

[0] https://github.com/sdroege/gobject-subclass/
[1] https://gitlab.gnome.org/federico/gnome-class
[2] https://github.com/gtk-rs/gir/pull/604
[3] https://github.com/sdroege/gst-plugin-rs
[4] https://github.com/sdroege/gtk-subclass
[5] https://github.com/sdroege/gobject-subclass/blob/master/gobject-subclass/tests/simple_object.rs
[6] 
https://github.com/gtk-rs/examples/blob/a34f83a0cd29a33e86890972ddcf684297ac6858/src/bin/listbox_model.rs#L232-L404
[7] https://github.com/sdroege/gobject-subclass/blob/master/gio-subclass/tests/simple_application.rs
[8] https://github.com/sdroege/gobject-subclass/tree/master/gio-subclass/src/custom
[9] https://github.com/sdroege/gobject-subclass/pull/14

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]