I am trying to pass a Python object into rust and perform operations using the fields of the Python object.
Python:
class myclass(object):
def __init__(self):
self.a = 3
b = myclass()
print(b.a)
// 3
Rust:
#[pyfn(m, "rust_obj")]
fn rust_obj_py(py: Python, x: PyObject) -> PyResult<PyObject> {
let y = x.clone_ref(py);
y.a += 2;
Ok(y)
}
Expected result when calling from Python would be:
c = rust_obj(b)
print(c.a)
// 5
Instead Rust error out when compiling:
error[E0609]: no field `a` on type `pyo3::PyObject`
--> src\lib.rs:926:5
|
926 | y.a += 2;
| ^ unknown field
Is there a way to list the object fields and methods in rust and manipulate the fields?