-
Notifications
You must be signed in to change notification settings - Fork 600
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
Serde struct #2727
Serde struct #2727
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR. This is a great start.
However, there is a bunch of things which doesn't make sense to serialize as is.
Because we probably should maintain compatibility over the serialization so we should be careful about that.
Also could you perhaps add a test. I'd say in api/rs/slint/tests/
The test should serialize and deserialize a slint struct and check they are equal, or something like that.
@ogoffart there are some error on test on uefi-demo and mcu . Edit: fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discussed this with @tronical and we think we should do this PR in several pieces.
-
Make our struct such as SharedVector and SharedString as serializable.
I think what you have there is good: A feature in slint, forwarded in i-slint-core to enable serialization of our structs. -
Then we can enable the serialization of struct declared in slint. But the question is whether this should be enabled by default as that may actually be a breaking change.
Maybe it should be opt-in per struct, or maybe it should be done only using import from Rust (Ability to import Rust and C++ struct as .slint struct #1726)
So now i think we should try to get the first part polished and merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So just to be clear, i think first we should only keep the changes in the internal/core library (and add a test there) and also a way to enable the feature from slint/Cargo.toml
Do we miss any of these ? What exactly should we do? |
The problem is that if we add in the generated code something like #[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
struct Foo {
...
} the Some idea include:
So this turns out to be harder than first thought. But for sure the first step is to allow SharedString and SharedVector to be serialized. |
@ogoffart |
Not sure what you mean. But what i mean is to have feature flag to implement serialize and deserialize on Slint's core types such as SharedVector and SharedString |
@ogoffart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the api/rs/slint/Cargo.toml , just add a feature to forward the core serde feature
## Enable the serialization and deserialization of Slint's core types by implementing
## the traits from the [serde](https://crates.io/crates/serde) crate
serde = ["i-slint-core/serde"]
@ogoffart is there any issue with it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost good.
Please move the test to core, and make sure it is being run on CI (we pass --all-features on our CI so it should normally be run)
Also move the feature a bit down in the file for the documentation.
@ogoffart done ? |
@ogoffart it can't be merge ? |
Yes, there are merge conflicts. Would you like me to rebase and merge it for you? |
@tronical Sure , Thanks :) |
@tronical is it done ? |
Yes, let's get this in. If you feel like digging further, one thing that would be nice is if the de-serialization into a SharedVector would be possible without the allocation of an intermediate Vec. |
@tronical I will do it these days , almost working to add serde feature in slint . |
fixes: #2660
Suppose missed some struct and should add serde features to toml but with cycle importing I suppose collabrators could help to solve it .