Replies: 1 comment
-
This will not work: Serde works by syntactically enumerating the fields at compile time and hence it cannot know about the dynamically created Python properties. I think using a Python-oriented JSON serializer like Python's built-in |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to use a "serde/serde-json" rust library to serialize and deserialize object to json and vice-versa. Areally simple implementation of which in rust would look something like this:
What I am trying to do is allow python users to create say
Point
objects in python and have it serialized and deserialized in rust like so:This results in
Point(3,2)
.What I have done here is that I have create a
General
struct aspyclass
that derivesSerialize
andDeserialize
implementations from serde library as a superclass in Rust andPoint
subclass in python. The intention is to allow any class that extendsGeneral
have the capability of being serialized and deserialized in rust. Then I have created apyfunction
calledpoint_serde
that is supposed to do the actual serialization and deserialization.When I try to print
point.as_ref()
, it returnsPoint(3,2)
correctly. But the type is&PyAny
. I am unsure how to passPoint
toserde_json::to_string(r)
asr
. Please suggest.Beta Was this translation helpful? Give feedback.
All reactions