leptess icon indicating copy to clipboard operation
leptess copied to clipboard

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

Open kangalio opened this issue 5 years ago • 2 comments

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

kangalio avatar Aug 03 '20 14:08 kangalio

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

ccouzens avatar Aug 05 '20 20:08 ccouzens

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

houqp avatar Aug 09 '20 23:08 houqp