-
-
Notifications
You must be signed in to change notification settings - Fork 62
GResource bindings #120
Comments
Binding GTypes is quite difficult and it takes time to determine what's the best way to do it. It'll be done, but I don't know when. cc @gkoz |
We'll generate some @sunnyone I think you can avoid extra copying by changing |
Thanks for replies and a advice! I'm looking forward to using new classes. |
The safe translation of the above should now be let bytes = glib::Bytes::from_static(include_bytes!("resources/resources.gresource"));
let res = gio::Resource::new_from_data(&bytes).unwrap();
gio::resources_register(&res); |
Thanks! |
I like this feature especially since it spares me keeping struggling with platform dependent resource paths. However I'm having some issues because Glib seems to need 8-byte-aligned data. If the data included via GLib:ERROR:/build/glib2.0-7IO_Yw/glib2.0-2.48.1/./glib/gvariant-serialiser.c:167:g_variant_serialised_check: assertion failed (alignment & (gsize) serialised.data == 0): (5 == 0) The C source file generated by # define SECTION __attribute__ ((section (".gresource.res"), aligned (8))) Unfortunately, Rust's |
I've got a temporary solution: If glib::Bytes copies the static data, it seems to be aligned (however I haven't found any documentation on this). // first make &[u8;...] unsized because &[u8;N] doesn't implement std::borrow::Borrow<[T]> for N>32
let resource_data: &[u8] = &include_bytes!("../res/res.gresource")[..];
let bytes = glib::Bytes::from(&resource_data);
let res = gio::Resource::new_from_data(&bytes).unwrap();
gio::resources_register(&res); Is there a reason for glib::Bytes::new() not being public? Using new() directly the first line (&...[..]) shouldn't be necessary. |
Yeah, I've encountered this in this build-helper prototype. I had to forego
I suppose large allocations are likely to be aligned but one can't really depend on that.
Not sure now but it might be making |
Does a plan exist to support GResource apis?
Nowadays some of gtk apis have _from_resource variations, so embedding GResource bytes with include_bytes! is convinient in gtk-rs programming.
Currently I use GResource with -sys crates directly, but it's ugly (the code is below).
(the full project source is here: https://github.com/sunnyone/gresource-gtkrs-example)
I lack the knowledge of Rust to create GResource binding, especially a part to determine correct lifetime of GResource. I hope a GResource binding will be implemented smartly.
The text was updated successfully, but these errors were encountered: