parity: fix UserDefaults json parser#9130
Conversation
|
Dumb question: why can't we use serde derive here instead? |
|
@ordian Seems like this code is a bit old so that's probably the reason. |
|
@andresilva I would prefer having derive, because it is more future-proof and less code to read - easier to reason about. As for |
|
F-Label Society 🤣 |
|
@5chdn Indeed 😆 I'm having a hard time learning not to use F-labels on PRs. |
|
@ordian I've updated the PR to use |
| // would fail. this way we keep the existing values for the other fields and | ||
| // only provide a default for the `mode` field in case it fails to | ||
| // deserialize. | ||
| Ok(Mode::deserialize(deserializer).unwrap_or(Mode::Active)) |
There was a problem hiding this comment.
Maybe we can preserve backwards compatibility like this?
There was a problem hiding this comment.
Nice! But apparently flatten can only be used with structs and maps:
2018-07-17 13:11:47 Error loading user defaults file: ErrorImpl { code: Message("can only flatten structs and maps"), line: 1, column: 107 }
Always prints that when starting although it seems to work. Also the serialization of Duration is different so also not backwards compatible.
(I didn't know you could use crates in rust playground that's super useful!)
There was a problem hiding this comment.
Ah, looks like we're using serde 1.0.37 and support for flattening internally tagged enums was only implemented in 1.0.46. The difference in UPD: Updated playground link (fixed Duration serialization is also probably due to different versions used in playground in parity codebase.Duration serialization).
(rust playground was merged with Integer32's playground implementation one year ago)
|
Updated serde and added the |
| pub struct Seconds(Duration); | ||
|
|
||
| impl Seconds { | ||
| pub fn value(&self) -> u64 { |
There was a problem hiding this comment.
There are some spaces left from copy-paste, please M-x tabify
|
@5chdn I've closed this PR and created a new one. It's the easiest way to overcome the CI issue. |
Fixes #8550.