I'm recently trying to use a small rust crate in python with pyo3, which resembles the following code:
#[pyclass]
struct my_struct {
my_path: &'static str,
my_map: HashMap<String, i32>,
my_num: i32,
my_map_of_map: HashMap<String, HashMap<String, f64>>,
}
#[pymethods]
impl my_struct {
#[new]
fn new(my_first_path: &'static str) -> Self {
Self {
my_first_path,
my_map: HashMap::new(),
my_num: 5,
my_map_of_map: HashMap::new(),
}
}
}
fn crate_name(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<my_struct>()?;
Ok(())
}
When I build the code with maturin however, the following error occurs:
`gil` does not live long enough
21 | #[pymethods]
| ^^^^^^^^^^^-
| | |
| | `gil` dropped here while still borrowed
| borrowed value does not live long enough
| cast requires that `gil` is borrowed for `'static`
Would there be any advice on how this error can be resolved?