Exposing entire struct at once to python (pyo3)

I'm a Rust newbie exploring language features. One important topic is Python interop for unit testing and modeling. I've got this far exposing a Rust struct:

#[pyclass]
pub struct RustStruct {
    #[pyo3(get, set)] integer: i32,
    #[pyo3(get, set)] float: f32
}

There are a few things that bother me about this:

  1. I have to set the accessibility for every member separately
  2. I have to modify the original struct code to expose it to Python. Unlike pybind11 for instance, where the original struct definition is untouched, and the pybind code exposes it to Python.
  3. The code won't compile in a setting where pyo3 is not present.

Ideally, I'd like to be able take existing Rust structures in an application, and say "please expose this to Python for me, in such a way that I can instantiate and modify the Rust structure in Python, and without having to modify the source code for the existing structure".

I hope this all makes sense. Are there ways to get closer to this goal?

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.