Skip to content

add serialize_with and deserialize_with attribute families for json/bin#114

Open
Adjective-Object wants to merge 3 commits intonot-fl3:masterfrom
Adjective-Object:adjective-object/deserialize_with
Open

add serialize_with and deserialize_with attribute families for json/bin#114
Adjective-Object wants to merge 3 commits intonot-fl3:masterfrom
Adjective-Object:adjective-object/deserialize_with

Conversation

@Adjective-Object
Copy link
Copy Markdown
Contributor

This change adds support for nanoserde's analogs for serde's serialize_with and deserialize_with field attributes.

nanoserde is designed to translate directly between the serialized format the in-memory representation. This requires splitting the attribute into separate attributes for each of the target formats, instead of the singular deserialize_with or serialize_with.


For context, I'm porting a library from serde to nanoserde to try to reduce binary size in a game I'm working on, and to facilitate that, I found it handy to bridge some of the feature gap between the libraries.
Let me know if you're okay with contributions in this vein. I generally like to upstream new features when maintainers are interested.

@not-fl3
Copy link
Copy Markdown
Owner

not-fl3 commented Oct 4, 2024

To preface this comment, note that I did not dig deep enough and I might not understand certain details.

But my first thought: would it be possible to use a proxy type with custom DeJson implementation to achieve the same result?

@Adjective-Object
Copy link
Copy Markdown
Contributor Author

Adjective-Object commented Oct 4, 2024

would it be possible to use a proxy type with custom DeJson implementation to achieve the same result

I am think that would work. I'm not 100% sure, but I think that incurs an extra copy from the deserialized proxy into the field, unless the proxy type has the exact same memory layout as the target type.

For clarity, are you saying that the library consumer should use proxy type, or that any deserialize_with attribute would generate a proxy struct to deserialize with?

@not-fl3
Copy link
Copy Markdown
Owner

not-fl3 commented Oct 4, 2024

I would at least try to implement the same tests with the proxy on the user level. Generally, I would usually choose slightly less user-space ergonomics for less implementation complexity, but it really depends on how much worth for the user, how much more complexity etc etc.

But I do not have any strong opinion on this yet, I am not saying that we should not have serialize_with!

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