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
{{ message }}
Repository navigation
Implement serialize_some and possibly serialize_none for serialization_serde #56
Options are currently not supported for serialization in the serialization_serde module. That makes it unnecessarily hard to use a common pattern like this where you have optional values that don't necessarily need to be present and should be left out when they are None:
This works fine for deserialization but runs into the unimplemented serialize_none and serialize_some functions for serialization. The None case can be easily avoided with #[serde(skip_serializing_if = "Option::is_none")], but in case of Some the value would have to be mapped.
It is totally possible that there is reason why the two functions are not implemented but right now I can't think of any reasons.
I would suggest to at least implement serialize_some to simply serialize the T value in Some(T) and I'd probably also implement serialize_none to not do anything.
Let me know what you think and if there are any reasons that made you not implement it. If you want I can also implement this and do a PR
Actually while writing this, I noticed that None values would have to be serialized by deleting existing values to stay consistent. If that was / is of concern I'd either implement exactly that (delete existing values in case of None), or just keep None values as unimplemented. Imo Some should still be implemented as in that case there are no consistency problems and devs have to manually handle the None case of Options anyway (due to it not being implemented)
Edit: both options are now in the branch. The latest commit implements value deletion and the one before that just ignores None values. I personally think it should delete None values, as you could simply use the #[serde(skip_serializing_if = "Option::is_none")] annotation to opt out of this behavior. The other way around there is no such option
Activity
dnlmlr commentedon Jun 26, 2023
I implemented this in master...dnlmlr:winreg-rs:feature-serialize_some_none.
No PR yet just in case I'm missing some major problem.
Actually while writing this, I noticed that
Nonevalues would have to be serialized by deleting existing values to stay consistent. If that was / is of concern I'd either implement exactly that (delete existing values in case ofNone), or just keepNonevalues as unimplemented. ImoSomeshould still be implemented as in that case there are no consistency problems and devs have to manually handle theNonecase of Options anyway (due to it not being implemented)Edit: both options are now in the branch. The latest commit implements value deletion and the one before that just ignores
Nonevalues. I personally think it should deleteNonevalues, as you could simply use the#[serde(skip_serializing_if = "Option::is_none")]annotation to opt out of this behavior. The other way around there is no such optiongentoo90 commentedon Jan 8, 2025
Fixed in
0.15.0(winapi)/0.53.0(windows-sys)gentoo90 commentedon Jan 8, 2025
Oops, I didn't think of deleting the
None. Will have to delete the keys too though.gentoo90 commentedon Jan 8, 2025
I opened a separate issue #76 for that