You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my application I have many "plain-old-data" structs, i.e. structs with only public fields that are supposed to be instantiated with the StructName { field1: ..., field2: ... } syntax in Rust.
Making those structs usable from Python-land currently involves a bit of avoidable boilerplate:
structStructName{#[pyo3(get, set)]pubfield1:u32,#[pyo3(get, set)]pubfield1:u32,}// this is the boilerplate I'm talking about#[pymethods]implStructName{#[new]pubfnnew(field1:u32,field2:u32) -> Self{Self{ field1, field2 }}}
This kind of class is equivalent to Python's dataclasses. Python's dataclasses include default constructors which is very convenient and sensible. I think it would be nice for PyO3 to do the same and automatically provide default constructors like above, for plain-old-data structs with all pub fields.
The text was updated successfully, but these errors were encountered:
Thanks for this suggestion. I've often wanted such a constructor generated for me. In combination with #1375, binding pod structs would be very convenient.
I don't think we want to enable this for all #[pyclass] structs automatically, at least not without a long period of making it opt-in and learning if anyone doesn't use the option.
I wondered in the past if this could be done as an external crate first (e.g. pyo3-pod-structs) to give us a first implementation to experiment with, though I haven't thought too hard about the design.
In my application I have many "plain-old-data" structs, i.e. structs with only public fields that are supposed to be instantiated with the
StructName { field1: ..., field2: ... }
syntax in Rust.Making those structs usable from Python-land currently involves a bit of avoidable boilerplate:
This kind of class is equivalent to Python's dataclasses. Python's dataclasses include default constructors which is very convenient and sensible. I think it would be nice for PyO3 to do the same and automatically provide default constructors like above, for plain-old-data structs with all
pub
fields.The text was updated successfully, but these errors were encountered: