#leptonica #image


Safe wrapper of leptonica-sys

9 releases (2 stable)

1.0.1 Feb 26, 2023
0.6.0 Aug 16, 2022
0.5.0 May 17, 2022
0.4.1 Dec 9, 2021
0.1.0 Mar 10, 2021

#70 in Images

Download history 136/week @ 2023-02-08 263/week @ 2023-02-15 306/week @ 2023-02-22 243/week @ 2023-03-01 250/week @ 2023-03-08 639/week @ 2023-03-15 583/week @ 2023-03-22 350/week @ 2023-03-29 461/week @ 2023-04-05 325/week @ 2023-04-12 199/week @ 2023-04-19 423/week @ 2023-04-26 535/week @ 2023-05-03 1973/week @ 2023-05-10 1377/week @ 2023-05-17 1288/week @ 2023-05-24

5,309 downloads per month
Used in 6 crates (via tesseract-plumbing)

MIT license

484 lines


Crate to expose a safe version of the leptonica-sys api.

This is designed to expose the C API of leptonica in a safe manner.

Adding value by deviating from the API is a non-goal. That is left to libraries that build on top of leptonica-plumbing.


I'm a maintainer of both leptess and tesseract-rs.

I noticed that there was a lot of duplication in how they interact with both leptonica-sys and tesseract-sys. Having multiple layers of abstraction in leptess and tesseract-rs made it hard to reason about their memory safety.

Having a safety layer that stays simple improves the correctness and maintainability of the above libraries.


To test for memory leaks, test with valgrind.

cargo test --release && valgrind --leak-check=yes --error-exitcode=1 --leak-check=full --show-leak-kinds=all "$(find target/*/deps/ -executable -name 'leptonica_plumbing-*')"

You may find that leptonica always leaks 16B of memory.

To test with a manually compiled Leptonica, test with additional environment variables

LD_LIBRARY_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib" PKG_CONFIG_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib/pkgconfig" cargo test

The two can be combined

LD_LIBRARY_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib" PKG_CONFIG_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib/pkgconfig" bash -c 'cargo test --release && valgrind --leak-check=yes --error-exitcode=1 --leak-check=full --show-leak-kinds=all "$(find target/*/deps/ -executable -name 'leptonica_plumbing-*')"'


~61K SLoC