Skip to content

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

@User-TGK

Description

@User-TGK

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<i32>,
}

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 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions