-
Notifications
You must be signed in to change notification settings - Fork 9
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
Serde support #32
Comments
Can we do both? The advantage of int is zero cost deseralizing. |
We could, if we think it's useful.
It's not zero-cost, because we still have to validate it. |
Another advantage of strings is that it would make it friendlier when consuming serialized data from other platforms that don't have TinyStr. The integer representation is sort-of internal to TinyStr in Rust. |
Thoughts on starting with string serialization, and considering it a feature request to add integer serialization? |
I agree with this approach. |
We can have an unchecked deserialize from int. But i agree we can start with string! |
This works for me! |
I can make a quick PR |
We can use |
I like that! If we do it, I would still prefer to validate the integers when deserializing, because data can come from unknown sources. If we want to do unchecked deserialization as Zibi mentioned above, that should be an opt-in mode. |
Sure, I agree. I believe that in environments where both input and output is guaranteed to be cohesive, the huge win of TinyStr is that it is an int that can be zero-cost deserialized. I'm ok with it being opt-in. |
Oh yeah we can never do this unchecked, but either way we're validating, this way we can validate a little less 😄 |
@gregtatum said in unicode-org/icu4x#480 that he can't put a TinyStr into a serde struct field because TinyStr doesn't support serde. We should add serde to TinyStr.
We could make the serialized representation either an integer or a string. I favor a string because it is more human-readable. In certain serialization forms, storing the integer form may be a bit smaller, either because you can omit the
""
or the string length header, but I don't think that's worth the readability. On the other hand, we could allow both forms and have a serde attribute that lets you switch between them when serializing.The text was updated successfully, but these errors were encountered: