Example project to extend python with rust and ctypes
pip install .
python
>>> import rust_python_ctypes
>>> rust_python_ctypes.hello_rust()
hello rust
Cargo.toml
[package]
name = "rust-python-ctypes"
version = "0.1.0"
authors = ["suzusuzu <s.suzugamine@gmail.com>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
src/lib.rs
#[no_mangle]
pub extern "C" fn hello_rust(){
println!("hello rust");
}
rust_python_ctypes/__init__.py
hello_rust_ = cdll.LoadLibrary(lib_path).hello_rust
def hello_rust():
hello_rust_()