rustdef
Jupyter extension for jupyter notebook and rust user.
Define functions in rust and then run as python funcions. This extension is built on PyO3 and maturin.
Examples
Magic command
Add dependencies
%rustdef depends CRATE...
Define rust functions
%%rustdef
#[pyfunction]
fn my_func(x: i64, y: &str) -> i64 {
println!("{}", y);
x + y.len() as i64
}
Develop
How it works?
Roughly, definitions in rustdef are available in python after the following steps.
- Each rustdef magic cell is populated with module definition of pyo3
- A new crate is generated for the rustdef cell
- The crate is compiled into a python wheel by
maturin
- Install the wheel with pip
- Functions with
#[pyfunction]
attributes are exported into interpreter name space in notebook - Ready to call the function in jupyter!
Build
maturin
is required.
$ pip install maturin
$ maturin build
$ pip install target/wheels/rustdef-{version}-{python}-{platform}.whl
ToDo
- execute within rustdef cell
- dependency crate version
- class/module supports
- customizable module name
- verbose flag
- syntax highlight
- serde support