-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntoPy and FromPyObject integration #1
Comments
I had a crate (closed source unfortunately) that does the same as pythonize. The idea is to opt in to custom serialization/deserialization. I exposed a choice as there are pros and cons with each:
(1) is transparent on the struct as it requires no changes to field types, whereas (2) is finer grained and can be applied like In terms of implementation, serialization works as follows:
Deserialization works by looking for the specially named field and treating it as a pointer. |
I would certainly appreciate this. My use case is as follows:
Example: use pyo3::prelude::*;
#[pyclass]
enum E {
Foo,
Bar,
}
#[derive(Serialize)]
struct S {
other_field: String
enum_field: E,
}
let s = S {
other_field: "potato".to_owned(),
enum_field: E:Foo,
}
pythonize::pythonize(py, &s) Then in python, this results in a out = {'other_field': 'potato', 'enum_field': 'Foo'}
from rust_module import E
E.Foo == out['enum_field'] # False :( |
At the moment I'm too busy to look into this myself; contributions are welcome. The proposal by @1tgr sounds like it could work as an opt-in mechanism! (I think to have something work automatically would require specialization, though I haven't thought too hard!) |
As currently designed,
pythonize
anddepythonize
on structs with bothSerialize
andIntoPy
implementations will always use theSerialize
implementation.I'm not sure if that's surprising - it's certainly predictable though.
Open point of discussion as to whether
pythonize
should attempt to re-use existingIntoPy
implementations, and if so, how could this be implemented?The text was updated successfully, but these errors were encountered: