houqp / leptess

Productive and safe Rust binding for leptonica and tesseract
https://houqp.github.io/leptess/leptess/index.html
MIT License
259 stars 29 forks source link

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

Open kangalio opened 4 years ago

kangalio commented 4 years ago

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:

https://github.com/kangalioo/leptess/commit/786a7519f904e7a6eafa9be18f8a5f201bff9120

ccouzens commented 4 years ago

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 commented 4 years ago

:+1: 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.