sys icon indicating copy to clipboard operation
sys copied to clipboard

Make certain structs derive Copy

Open qdot opened this issue 7 years ago • 5 comments

I'm working on https://github.com/qdot/libappindicator-sys, which will use gtk-sys for some of the symbols it needs to fill in for function arguments. I'd like to use other g*-sys crates to fill in things like GObject/GType/GTypeClass/etc that are used as struct field types.

The problem is that I'm using bindgen for my library, and it creates all structs as #[derive(Debug, Copy)]. Since none of the G* structs impl Copy, I'm stuck using the versions that bindgen creates. It works, but it'd be nice to have everything provided from the g*-sys crates if possible.

Here's the commit where I brought this up on the project

https://github.com/qdot/libappindicator-sys/commit/e3f9ce63f2a811cd00f0a1d6b1a937df49e846b3#commitcomment-21061033

cc @jonhoo

qdot avatar Feb 27 '17 04:02 qdot

From a very cursory glance at the codebase, it looks like this is something that would need to be implemented in https://github.com/gtk-rs/gir. Maybe @EPashkin can confirm? In particular, I'm guessing Copy can't be derived for all the generated types (e.g., things with pointers)?

jonhoo avatar Feb 27 '17 04:02 jonhoo

@qdot, as @jonhoo says types for that Copy derived must don't contains pointers. On fast glance I found only 3 of these in gtk-sys: GtkBorder, GtkPageRange, GtkRequisition While I can add generating #[derive(Debug, Copy)] for them IMHO better do it on upper level (ex. not in GdkRectangle, but in gdk::Rectangle). Currently Gir don't support generating upper level struct from these "direct" so all these struct currently manually written when needed, and seems Border, PageRange, Requisition not present in gtk-rs\gtk crate.

EPashkin avatar Feb 27 '17 06:02 EPashkin

@EPashkin Problem with doing it at the gdk::* level is that we'd still have problems with what I'm trying to do for bindgen, since I'm running lower than that level. For instance, with libappindicator, bindgen just hands me something like this:

#[repr(C)]
#[derive(Debug, Copy)]
pub struct _AppIndicator {
    pub parent: GObject,
    pub priv_: *mut AppIndicatorPrivate,
}

I'd still need the gobject-sys to provide me a Copy derived version, since that struct is supposed to be a direct representation of the C struct. Right now, my bindings file just has its own bindgen-generated GObject implementation that does that.

qdot avatar Feb 27 '17 06:02 qdot

I don't like idea copying classes structure's without using glib-provided functions. Can you show example when it really needed?

EPashkin avatar Feb 27 '17 07:02 EPashkin

I suppose it's not really needed in that things work as is right now, and I really don't expect anyone to be playing with the innards of the bindgen-generated structs in libappindicator-sys. It just seemed like it might be nice to not have bindgen redefine types provided by gobject-sys and other crates if I didn't have to.

qdot avatar Feb 27 '17 07:02 qdot