-
-
Notifications
You must be signed in to change notification settings - Fork 58
Surface.create_similar() should return a Result #251
Comments
Yes, and probably the same for various other functions. Someone should go through them all at some point. |
@federicomenaquintero Thanks for fixing |
This one is not fixed yet :) |
Damn, just got a librsvg bug where we panicked because Surface.create_similar() always returns a Surface 😞 I've started fixing this. My first cut is to turn I have a question about this: #[cfg(feature = "use_glib")]
impl FromGlibPtrFull<*mut ffi::cairo_surface_t> for Surface {
#[inline]
unsafe fn from_glib_full(ptr: *mut ffi::cairo_surface_t) -> Surface {
Self::from_raw_full(ptr).unwrap()
}
} This is.... wrong? Or did we ever discuss this - the unwrap() seems perilous? |
…esult Cairo's surface creation functions never return NULL; instead they always return a surface, but it may be in an error state. In gtk-rs#141 we started making the binding functions return Result for this; some returned the plain FooSurface type, some others Option<FooSurface>. This makes the following functions return Result<FooSurface, Status> Surface::create_similar() Surface::create_similar_image() RecordingSurface::create() Device.surface_create() Device.surface_create_for_target() The foundation for all of this is that Surface::from_raw_full() now also returns Result<FooSurface, Status>. This is to make things consistent with ImageSurface::from_raw_full(). Analogously, we now have RecordingSurface::from_raw_full() that also returns Result. Fixes gtk-rs#251
That's correct. If all you want to have returned is a concrete value instead of an Option, then the only thing we can do here is to panic if we get NULL or it doesn't work otherwise. The Option FromGlibXXX impls would do the right thing and not panic. |
And maybe better add function to |
|
@sdroege No, I meant in function that must return Option. |
Oh, ignore this idea, I wrongly understand main issue |
Actually I thought about something like
maybe with
|
…esult Cairo's surface creation functions never return NULL; instead they always return a surface, but it may be in an error state. In gtk-rs#141 we started making the binding functions return Result for this; some returned the plain FooSurface type, some others Option<FooSurface>. This makes the following functions return Result<FooSurface, Status> Surface::create_similar() Surface::create_similar_image() Device.surface_create() Device.surface_create_for_target() PdfSurface::new() RecordingSurface::create() RecordingSurface::from_raw_full() SvgSurface::new() XCBSurface::create() XCBSurface::create_for_bitmap() XCBSurface::create_with_xrender_format() From macro for_stream_constructors!: *::for_stream() *::for_raw_stream() The foundation for all of this is that Surface::from_raw_full() now also returns Result<FooSurface, Status>. This is to make things consistent with ImageSurface::from_raw_full(). Analogously, we now have RecordingSurface::from_raw_full() that also returns Result. Fixes gtk-rs#251
@EPashkin I'm using your |
…lar-result (#251): Surface::create_similar() and friends should return a Result
As in #141,
cairo_surface_create_similar()
will never return NULL, but it may return acairo_surface_t *
with an error status. I thinkSurface::create_similar()
should return aResult<Surface, Status>
.The text was updated successfully, but these errors were encountered: