Skip to content

Commit b01b6c2

Browse files
committed
Fix bug in SerdeDerive macro implementation
1 parent e461da4 commit b01b6c2

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

serde-diff-derive/src/serde_diff/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ fn generate(
332332
match (self, other) {
333333
#(#diff_match_arms)*
334334
}
335+
if (__changed__) {
336+
ctx.save_exit()?;
337+
}
335338
Ok(__changed__)
336339
}
337340
}

src/difference.rs

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ impl<'a, S: SerializeSeq> DiffContext<'a, S> {
148148
self.save_command(&DiffCommandRef::Value(value), true, true)
149149
}
150150

151+
/// Write exit command
152+
pub fn save_exit(&mut self) -> Result<(), S::Error> {
153+
self.save_command::<()>(&DiffCommandRef::Exit, true, false)
154+
}
155+
151156
/// Stores an arbitrary DiffCommand to be handled by the type.
152157
/// Any custom sequence of DiffCommands must be followed by Exit.
153158
pub fn save_command<'b, T: Serialize>(

src/tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate as serde_diff;
22
use crate::{Apply, Diff, SerdeDiff};
33
use serde::{Deserialize, Serialize};
4+
use std::collections::HashMap;
45
use std::fmt::Debug;
6+
use std::iter::FromIterator;
57

68
#[derive(SerdeDiff, Serialize, Deserialize, PartialEq, Debug, Copy, Clone)]
79
struct TestStruct {
@@ -59,6 +61,18 @@ fn test_option() {
5961
Some(TestStruct { a: 52, b: 32. }),
6062
Some(TestStruct { a: 42, b: 12. }),
6163
);
64+
roundtrip(
65+
HashMap::from_iter([
66+
(1, TestStruct { a: 1, b: 1. }),
67+
(2, TestStruct { a: 2, b: 2. }),
68+
(3, TestStruct { a: 3, b: 3. }),
69+
]),
70+
HashMap::from_iter([
71+
(1, TestStruct { a: 1, b: 1. }),
72+
(3, TestStruct { a: 4, b: 4. }),
73+
(4, TestStruct { a: 1, b: 1. }),
74+
]),
75+
);
6276

6377
partial(
6478
Some(TestStruct { a: 5, b: 2. }),

0 commit comments

Comments
 (0)