amethyst / amethyst/serde-diff

Derived "apply" implementation for enums is broken

Aperta
#35 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
127
Fork
21
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

When diffing an enum like:
```rust
#[derive(SerdeDiff, Serialize, Deserialize, Debug, PartialEq, Clone)]
enum Value {
Str(String),
Int(i32),
}
```

Let's say we have the diff `Value::Str("A") -> Value::Str("B")`.

The diff implementation will produce the following sequence of commands:
```rust
[{"Enter":{"EnumVariant":"Str"}},{"Enter":{"FieldIndex":0}},{"Value":"B"},"Exit"]
```

However, the apply implementation does not consume the final `Exit` command, causing the rest of the command stream to get out of sync.

This is because of this code:
https://github.com/amethyst/serde-diff/blob/e461da41c9339af3ecadf9f4aa61ae91c1f79e97/serde-diff-derive/src/serde_diff/mod.rs#L362-L379

Specifically it's because `next_path_element` is only called once, instead of being called until it finds an `Exit` command. It makes sense to only call it once because an enum can only have one variant, but since the variant still counts as a path segment, an additional Exit should be consumed.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.