Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: hide format deserializer state type #34

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

leostera
Copy link
Member

@leostera leostera commented Jul 3, 2024

tldr: go from (Serde_json.De.state, User.t) Serde.De.t to User.t Serde.De.t

This refactor should make the ergonomics of Serde much better for library authors that need to provide flexibility on the format deserializer type, by making the format deserializer state type go away or be hidden at least from the user facing code.

We've first observed this when working on DbCaml with @emilpriver and noticed that a common error was unifying the types of the state of the format deserializer, which wasn't known in some cases by design, to allow a user to switch up which database format deserializer module they wanted to use (Postgres, SQLite, etc).

This change hides away the state of the context object passed around
between deserialization calls, which makes the `Serde.De.t` value take a
single type parameter for the type of value it is deserializing into.

That means that `(Serde_json.De.state, User.t) Serde.De.t` becomes
`User.t Serde.De.t` – this frees the user to swap out the format module
at runtime, and should make type errors simpler as well.
@leostera leostera force-pushed the hide-format-deserializer-state-type branch from 8fab82d to ec5a85a Compare July 3, 2024 21:34
@leostera leostera marked this pull request as ready for review July 3, 2024 21:38
@leostera leostera requested a review from tjdevries July 3, 2024 21:38
@leostera
Copy link
Member Author

leostera commented Jul 3, 2024

Confirmed with the bug repro repo (leostera/serde-de-state-bug-repr@174d240) and with @emilpriver that this works for DbCaml too.

Merging 🚀

@leostera leostera merged commit fb89819 into main Jul 3, 2024
0 of 4 checks passed
@leostera leostera deleted the hide-format-deserializer-state-type branch July 3, 2024 22:12
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