Skip to content
Rudimentary example of calling rust from cython
Branch: master
Clone or download
Latest commit f707538 May 27, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Initial commit May 27, 2015
.gitignore Initial commit May 27, 2015
Cargo.toml
README.md Create README.md May 27, 2015
cytest.pyx
rlib.h
setup.py Initial commit May 27, 2015

README.md

rust-cython-test

A rudimentary example of calling rust from cython

I've seen a number of examples of calling Rust from python, including Dan Callahad's talk at PyCon, this example from J. Clifford Dyer as well as in the official Rust book. All of the examples have used either the ctypes built-in module or CFFI.

Here is a simple example of calling a function defined in rust that doubles a double from within Cython. The example basically relies on the formalism that one would use to call Rust from C. This involves writing a .h header file and linking to the dynamic library generated by rust via the setup.py file.

Basic instructions for running the example:

cargo build --release
python setup.py build_ext --inplace

Then launching IPython:

In [1]: import cytest

In [2]: cytest.call_rust_double(10.0)
Out[2]: 20.0

This example is obviously not very useful, but I wanted to demonstrate the capability.

You can’t perform that action at this time.