Skip to content

fix: Prefix when serializing nested struct#7

Merged
lucagoslar merged 2 commits into
lucagoslar:mainfrom
LauH1987:nested_struct_prefix_fix
May 15, 2026
Merged

fix: Prefix when serializing nested struct#7
lucagoslar merged 2 commits into
lucagoslar:mainfrom
LauH1987:nested_struct_prefix_fix

Conversation

@LauH1987
Copy link
Copy Markdown
Contributor

@LauH1987 LauH1987 commented May 15, 2026

The current implementation doesn't "pop" the prefix correctly when finishing serializing a nested struct. This leaves the prefix from the nested struct lingering and adds it to any field that is being serialized afterwards. This happens because ser.prefix_before.clone() is called after the serialization of the nested struct has already changed the prefix_before.

I've added some tests to show the behavior. Here's an example of one of the tests running on the current main branch. The serialized struct looks like:

Outer {
    a: 1,
    inner: Inner { x: 2 },
    b: 3,
}
running 1 test
test ser::tests::serialize_to_string_struct_field_after_nested ... FAILED

failures:

---- ser::tests::serialize_to_string_struct_field_after_nested stdout ----

thread 'ser::tests::serialize_to_string_struct_field_after_nested' (87451) panicked at src/ser.rs:660:9:
assertion `left == right` failed
  left: "A=1\nINNER_X=2\nB=3"
 right: "A=1\nINNER_X=2\nINNER_B=3"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    ser::tests::serialize_to_string_struct_field_after_nested

As showed b gets serialized with the INNER_ prefix.

@lucagoslar lucagoslar merged commit 183c8c9 into lucagoslar:main May 15, 2026
1 check passed
@lucagoslar
Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants