-
-
Notifications
You must be signed in to change notification settings - Fork 20
Update RGBA/Rectangle FromValueOptional impls for newly added lifetim… #157
Update RGBA/Rectangle FromValueOptional impls for newly added lifetim… #157
Conversation
What would be the correct way to implement this for e.g. &RGBA? I could just do (with NULL checks, etc): &*(gobject_ffi::g_value_get_boxed(value.to_glib_none_mut().0) as *const RGBA) But I would expect that there is some infrastructure for that already? FromGlibPtrBorrow sounds like what I need, but I'm not sure how that is supposed to work. Should this be the following? impl<'a> FromGlibPtrBorrow<*mut gdk_ffi::RGBA> for &'a RGBA {
unsafe fn from_glib_borrow(ptr: *mut gdk_ffi::RGBA) -> Self {
the_code_from_above
}
} |
@sdroege Sorry I don't understand what you want to do. Don't see any link between GValue and FromGlibPtrBorrow. |
Current version works, but it will always copy the Rectangle/RGBA. I guess not really important for these cases, but it could also just return a (immutable) reference to them as stored inside the Value. Question is if there is some infrastructure somewhere to convert a *const gdk_ffi::RGBA to a &gdk::RGBA, or if there should just be the cast as above. FromGlibPtrBorrow sounds like it would do something like that, but I don't fully understand how that's supposed to work. |
You mean something like this?
It compiles, but not sure that it don't conflict with default implementation and don't cause memory problem |
|
They don't need to be copied, but it probably doesn't hurt much to always copy these structs. The above compiles and works and was exactly what I meant (and is safe to do), but I wasn't sure if there is infrastructure for such casts already. And FromGlibPtrBorrow sounded like it could do exactly that. |
impl<'a> FromGlibPtrBorrow<*const gobject_ffi::GValue> for &'a RGBA {
unsafe fn from_glib_borrow(value: *const gobject_ffi::GValue) -> Self {
let ptr = gobject_ffi::g_value_get_boxed(value) as *mut RGBA;
&*ptr
}
} Can exist too, but it right variant |
@GuillaumeGomez restart CI here please |
Why not? I'll take a look at that tomorrow, but in any case not too important for these types :) |
Restarted. |
@GuillaumeGomez CI passed |
Thanks to both of you! |
…e parameter
See gtk-rs/glib#162
As a next step, these two impls can actually benefit from being there for &Rectangle and &RGBA too to prevent some copying. I'll add those later.