Binding regex from Python


#1

I have a need for using the regex crate from Python (translation: Python <-> C <-> Rust). I’ve tried 3 different approaches, and they all have their downsides.

My first attempt was using cffi and manually writing simple FFI functions in Rust [1].
This attempt I’m not confident in, as I’m sure there are gotchas that I’m not aware of.

After doing more research, I discovered the existing C binding (rure).
My second attempt was to write a simple wrapper of rure, to make it easy to build a binary wheel for Python [2].
This attempt failed, and I’m not familiar enough with Rust (or C) to figure out why.
I tried several variations of wrapping rure, but they all failed in similar ways (either Python’s cffi responding with symbols missing from the library, or null pointers for structs).

My 3rd attempt was to forego the wrapper and instead include the small amount of Python code directly in the regex-capi crate [3].
I don’t mind maintaining a fork in my personal GitHub account for this glue code, but that seems flaky.
I also don’t want to foist maintaining Python bindings on the regex maintainers (as it seems rure-go was split out to a distinct repo [4])

  1. https://github.com/davidblewett/rusty-re
  2. https://github.com/davidblewett/rure-python
  3. https://github.com/rust-lang-nursery/regex/compare/master...davidblewett:rure-python?expand=1
  4. https://github.com/BurntSushi/rure-go