Consider a simple rust class exposed via pyo3 to python
use pyo3::prelude::*;
#[pyclass(name=MyClass)]
pub struct PyMyClass {
// Some fields
}
#[pymethods]
impl PyMyStruct {
#[new]
fn py_new(obj: PyRawObject) {
obj.init({
PyMyStruct {
// ...
}
});
}
}
now there is a function which should be called with two of this structs from python in that manner:
a = MyStruct()
b = MyStruct()
c = foo(a,b)
Therefore one defines
#[pyfunction]
fn foo(a: PyMyStruct, b: PyMyStruct) -> PyResult<PyMyStruct> {
// some high performance logic implemented in rust ...
}
Now the compiler claims PyMyStruct
should implement the trait FromPyObject
:
impl FromPyObject<'_> for PyMyStruct {
fn extract(ob: &'_ PyAny) ->PyResult<Self> {
// I dont know what to do here :(
}
}
But I dont know how to retrieve an instance, pointer or whatever of PyMyStruct
from PyAny
...
Can someone help me?