amethyst / amethyst/serde-diff

Apply Option difference to `None` target doesn't work as expected

Open
#28 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
127
Forks
21
PR merge metrics
No merged PRs in 30d

Description

#### Example to reproduce the issue

```
use serde::{Deserialize, Serialize};
use serde_diff::{Apply, Diff, SerdeDiff};

#[derive(SerdeDiff, Serialize, Deserialize, PartialEq, Debug, Clone)]
struct TestStruct {
a: Option,
}

fn main() {
let old = TestStruct { a: Some(5) };
let new = TestStruct { a: Some(10) };
let mut target = TestStruct { a: None };
let expected = new.clone();

let diff = Diff::serializable(&old, &new);
let json_diff = serde_json::to_string(&diff).unwrap();
let mut deserializer = serde_json::Deserializer::from_str(&json_diff);

Apply::apply(&mut deserializer, &mut target).unwrap();

assert_eq!(target, expected);
}
```

#### Expected result

For target to equal `TestStruct { a: Some(10) }`

#### Actual result

Target equals `TestStruct { a: None }`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.