Table of contents

Interfacing Rust module with Python, Android, JS

potential_post

%3 cluster_8a9c0205_02eb_4e4b_b483_e0ff20bff94c Interfacing Rust module with Python, Android, JS _59b6ddf5_dd5d_4aa4_9697_4d8da8f25348 Base Rust code _e36825c2_95d4_4f2a_8be6_db3acbf5b31a Interfacing with Python _adc661ba_4906_4e74_97ab_ae16f002aaf2 Python _e36825c2_95d4_4f2a_8be6_db3acbf5b31a->_adc661ba_4906_4e74_97ab_ae16f002aaf2 _53d3f074_512c_4bdd_b270_0bb1e8b7ca84 QUESTION What's the difference between Pyo3 and other binding types? _1c403d08_61f2_4df4_be90_90b8bffba03a Interfacing with JS _25a365cd_e157_4bf9_b873_10d34faa2054 Javascript _1c403d08_61f2_4df4_be90_90b8bffba03a->_25a365cd_e157_4bf9_b873_10d34faa2054 _bfe9e26e_e3a8_4e83_ac68_b66d3ce8ec4c Interfacing with Android _eedb166d_c224_4fb7_a0ee_1f176e8c82e7 Rust __0:cluster_8a9c0205_02eb_4e4b_b483_e0ff20bff94c->_eedb166d_c224_4fb7_a0ee_1f176e8c82e7

Base Rust code

  • Create library base

cargo new --vcs git --lib demo_rust_multitarget

Avoid - for better compatibility with Python module imports.

DONE

Interfacing with Python

mkdir demo_rust_multitarget
cd demo_rust_multitarget
python -m venv .env
source .env/bin/activate
pip install maturin
maturin init
# Select pyo3 as binding type
maturin develop
python3 -c 'import demo_rust_multitarget;print(demo_rust_multitarget.sum_as_string(1,2))'
# (Output) 3

Avoid - on project name for better compatibility with Python module imports.