Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More idiomatic return values (Option or Result instead of bool) #22

Open
kangalio opened this issue Aug 3, 2020 · 2 comments
Open

More idiomatic return values (Option or Result instead of bool) #22

kangalio opened this issue Aug 3, 2020 · 2 comments

Comments

@kangalio
Copy link
Contributor

kangalio commented Aug 3, 2020

In LepTess::set_image, bool is used as a return value to indicate success or failure. Booleans are not a good choice for a return value for this use case. Better is Option<()> or Result<(), ()> (I personally think Option<()> is nicer, but Result<(), ()> objectively makes more sense)

As a side-effect of this, the code inside the functions can become much more concise and idiomatic:

kangalio@786a751

@ccouzens
Copy link
Collaborator

ccouzens commented Aug 5, 2020

Good idea. I don't know what @houqp's opinion on changing the API is. Leptess hasn't had its 1.0.0 release, so API changes should be ok.

I suppose another alternative would be to return something like this

Result<(), Leptess::Error>

Where Error is an enum with a PixReadError variant

@houqp
Copy link
Owner

houqp commented Aug 9, 2020

👍 on this breaking change, If there is extra error context we can pass back to caller, we should use Result, otherwise, Option would be better.

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

No branches or pull requests

3 participants