
I - Install pip package
pip install maturin
II - Create project
maturin new --bindings pyo3 --mixed name_project
III - Create rust lib
Create insrc
matrix.rs
with your code like this
userand::Rng;pubfngenerate_matrix()->Vec<Vec<i32>>{letmutmatrix=vec![];for_in0..10{letmutrow=vec![];for_in0..10{row.push(rand::thread_rng().gen_range(0..100));}matrix.push(row);}matrix}
Insrc/lib.rs
add your code like this :
modmatrix;#[pyfunction]fnrandom_matrix()->Vec<Vec<i32>>{matrix::generate_matrix()}
And functions in the python module like this :
#[pymodule]fnmy_project(m:&Bound<'_,PyModule>)->PyResult<()>{m.add_function(wrap_pyfunction!(random_matrix,m)?)?;Ok(())}
IV - Compile
maturin build && pip install .
V - Test
Inpython/name_project/test/
for exemple, create one file with this and run it.
importmy_projectmatrix=my_project.random_matrix()print(matrix)
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse