2021-10-03 19:37:17 +00:00
|
|
|
use pyo3::prelude::*;
|
|
|
|
use pyo3::types::{PyCFunction, PyDict, PyTuple};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let fun: Py<PyCFunction> = Python::with_gil(|py| {
|
|
|
|
let local_data = vec![0, 1, 2, 3, 4];
|
|
|
|
let ref_: &[u8] = &local_data;
|
|
|
|
|
2024-02-23 14:07:54 +00:00
|
|
|
let closure_fn =
|
|
|
|
|_args: &Bound<'_, PyTuple>, _kwargs: Option<&Bound<'_, PyDict>>| -> PyResult<()> {
|
|
|
|
println!("This is five: {:?}", ref_.len());
|
|
|
|
Ok(())
|
|
|
|
};
|
2024-02-05 07:51:18 +00:00
|
|
|
PyCFunction::new_closure_bound(py, None, None, closure_fn)
|
|
|
|
.unwrap()
|
|
|
|
.into()
|
2021-10-03 19:37:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
fun.call0(py).unwrap();
|
|
|
|
});
|
|
|
|
}
|