How can I keep Rust data when sending PyClass to python #2903
Answered
by
adamreichold
shenjackyuanjie
asked this question in
Questions
-
I want to send this py class back to python #[pyclass(name = "PartDatas")]
pub struct PartDatas {
pub part_structs: HashMap<usize, SR1PartData>
}
#[pymethods]
impl PartDatas {
#[new]
pub fn py_new(py_part_data: &PyDict) -> PyResult<Self> {
let datas: HashMap<usize, SR1PartData> = part_data_tp_SR1PartDatas(py_part_data)?;
// let datas: HashMap<usize, SR1PartData> = HashMap::new();
return Ok(PartDatas { part_structs: datas })
}
// pub fn get_rust_data(&self) -> PyResult<Box<T>> {
// return Ok(self.part_structs);
// }
} |
Beta Was this translation helpful? Give feedback.
Answered by
adamreichold
Jan 24, 2023
Replies: 1 comment 2 replies
-
I am not sure I understand the problem correctly, but did you try to put the |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
shenjackyuanjie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am not sure I understand the problem correctly, but did you try to put the
get_rust_data
method into a separate impl block with#[pymethods]
? (I assume you want to access the internals from the Rust side, not from the Python side.)