5 ms·
A neat case study, but "Embedding Rust in Python" is a poor way to phrase it. If I'm reading it correctly they're just using CFFI to load and call a shared lib
by jlarocco 10y ago
A neat case study, but "Embedding Rust in Python" is a poor way to phrase it.
If I'm reading it correctly they're just using CFFI to load and call a shared library - it's really not embedding anything. The fact that the library was written in Rust is interesting, but as far as Python is concerned it could easily have been written in any language that can create a shared library.
- byronyi 10y agoIndeed. A more interesting comparison would be between C/C++ based shared library and Rust based one.
- lqdc13 10y agoOr how about Rust-FFI, C-FFI, C-API directly, Nim-to-C-API (pymod), Julia python module, ctypes, cython, libboost, and swig for a good measure. There are examples of each of these compared to one or the other but it would be nice to see all of them compared in a few benchmarks.
- monkeyshelli 10y agoOne benchmark to rule-them-all would sound awesome!
- the_mitsuhiko 10y ago> If I'm reading it correctly they're just using CFFI to load and call a shared library - it's really not embedding anything. The fact that the library was written in Rust is interesting, but as far as Python is concerned it could easily have been written in any language that can create a shared library. Of which there are not that many that would make a shared library that can be safely loaded into a Python process. Traditionally this was limited to C and C++. As far as embedding goes: Rust like most things needs minimal runtime support and that is embedded in the dylib.
- jlarocco 10y agoFWIW, most languages that can generate native code can generate shared libraries, and will usually have instructions for how to call the libraries from other languages. Here's how to do it Haskell, for example: https://downloads.haskell.org/~ghc/7.6.3/docs/html/users_guide/using-shared-libs.html https://downloads.haskell.org/~ghc/7.6.3/docs/html/users_gui... That said, if optimization gets to the point where re-writing in a different language is a good idea, most people just jump to C or C++, or in this case Rust, because they're the fastest.