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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Adjective-Object
Copy link
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
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
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
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