Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Implement Error trait for cairo::Success #320

Closed
bilelmoussaoui opened this issue May 28, 2020 · 5 comments · Fixed by #322
Closed

Implement Error trait for cairo::Success #320

bilelmoussaoui opened this issue May 28, 2020 · 5 comments · Fixed by #322

Comments

@bilelmoussaoui
Copy link
Member

I will send a merge request for this one

@sdroege sdroege mentioned this issue May 28, 2020
40 tasks
@sdroege
Copy link
Member

sdroege commented May 28, 2020

And change it to cairo::Error with only the error cases, and convert to Result<T, cairo::Error> where current cairo::Status::Success maps to Ok and the other things to Err :)

@bilelmoussaoui
Copy link
Member Author

I have a few questions:

  • I noticed a lot of ensure_status() which just get the status of X and calls ensure_valid() which itself just checks if the Status is Success or not. I don't think it makes sense to keep any of those around any more, does it?
  • the ensure_status() is called at unexpected places sometimes, where we assume we will not have a Result<T, cairo::Error> at all, for example https://github.com/gtk-rs/cairo/blob/master/src/font/font_options.rs#L41. Does it make more sense to just convert to a Result<T, cairo::Error> there as well?
  • a bunch of cairo objects exposes a pub fn status(&self) -> Status, does it make sense to still expose that? it might be useful in some weird use cases but doesn't look right in Rust. We should probably remove that and just return a Result whenever something might fail.

My questions are not super clear, sorry for that :)

@sdroege
Copy link
Member

sdroege commented May 29, 2020

* I noticed a lot of `ensure_status()` which just get the status of  X and calls `ensure_valid()` which itself just checks if the `Status` is `Success` or not. I don't think it makes sense to keep any of those around any more, does it?

I guess those could still stay around as Result<(), cairo::Error>... not sure why they exist at all, shouldn't operations that cause things to fail return a Result instead? But that needs some more investigation so I would do the removal of those as a second step.

* the `ensure_status()` is called at unexpected places sometimes, where we assume we will not have a Result<T, cairo::Error> at all, for example https://github.com/gtk-rs/cairo/blob/master/src/font/font_options.rs#L41. Does it make more sense to just convert to a Result<T, cairo::Error> there as well?

I assume creating a FontOptions can fail? As is this is a bit useless, it should either not check it (-> it can't fail) or it should return a Result like you suggest.

* a bunch of cairo objects exposes a `pub fn status(&self) -> Status`, does it make sense to still expose that? it might be useful in some weird use cases but doesn't look right in Rust. We should probably remove that and just return a Result whenever something might fail.

I agree, but same as with the (public!) ensure_status() I think this needs some more research though, same as above.

Does this help?

@bilelmoussaoui
Copy link
Member Author

bilelmoussaoui commented Jun 1, 2020

I'm thinking of doing a first merge request and check the API for each method that might fail and remove the unneeded ensure_status() as a first step and then move the whole thing to use a cairo::Error where it make sense. Does it sounds good to you? thanks for the feedback & help

@sdroege
Copy link
Member

sdroege commented Jun 1, 2020

Sounds like a plan. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants