Skip to content

deserializer: unit fields shift later columns when using headers - #440

Open
patrick-immometrica wants to merge 1 commit into
BurntSushi:masterfrom
patrick-immometrica:fix-deserialize-unit-headers
Open

patrick-immometrica wants to merge 1 commit into
BurntSushi:masterfrom
patrick-immometrica:fix-deserialize-unit-headers

Conversation

@patrick-immometrica

Copy link
Copy Markdown

A () or unit struct field in a struct read with headers doesn't consume its column, so every field after it is off by one:

#[derive(Deserialize)]
struct Row { a: String, b: (), c: String }
// "a,b,c\n1,2,3" -> c == "2"

In map mode the key comes from the headers, but deserialize_unit / deserialize_unit_struct never read the value from the record. Same thing happens with PhantomData.

The fix reads (and drops) the field when headers are in use. It doesn't fail if there's no field left, so deserializing an empty record as () still works. Without headers nothing changes, since a PhantomData field there currently takes no column and people may rely on that.

In map mode the key is read from the headers and the value from the
record. `deserialize_unit` and `deserialize_unit_struct` never touched the
record, so a `()` or unit struct field left its column unread and every
field after it got the value of the column before it.

Without headers nothing changes, so `PhantomData` fields there still don't
take a column.
@patrick-immometrica
patrick-immometrica marked this pull request as ready for review November 14, 2026 11:11
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.

1 participant