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

Lossless primitive types #241

Closed
cart opened this issue May 26, 2020 · 5 comments · Fixed by #481
Closed

Lossless primitive types #241

cart opened this issue May 26, 2020 · 5 comments · Fixed by #481
Labels
feature A new feature for the syntax or library. good first issue Perfect for new contributors help wanted

Comments

@cart
Copy link
Contributor

cart commented May 26, 2020

I'm using ron to deserialize types that are not known at compile time. It would be really nice to have the option to fully encode primitive types in ron so that type information isn't lost.

Ex: if i serialize 1u32, it will be written as 1. If I then deserialize it using deserialize_any, it will become 1u8 because it falls into the u8 range.

If instead 1u32 got serialized as 1u32, this would not be an issue. It would also allow ron to skip the any_num range checks.

I propose a new PrettyConfig::explicit_primitive_types option that enables this behavior.

@kvark
Copy link
Collaborator

kvark commented May 27, 2020

That sounds quite reasonable to me 👍
The only concern is that this is just one more step towards the format being self-describing, and we know that we aren't going to reach there. For example, you can't reconstruct an enum type efficiently just by looking at its variants.

@cart
Copy link
Contributor Author

cart commented May 27, 2020

Fortunately my use case doesn't require it to be fully self describing. This is the only change I want. It's just a small iterative improvement to an already working system.

@github-actions
Copy link

Issue has had no activity in the last 180 days and is going to be closed in 7 days if no further activity occurs

@github-actions github-actions bot added the stale label Nov 18, 2021
@kvark kvark reopened this Dec 3, 2021
@kvark
Copy link
Collaborator

kvark commented Dec 17, 2021

comment

@kvark kvark reopened this Dec 17, 2021
@github-actions github-actions bot removed the stale label Dec 18, 2021
@juntyr juntyr added help wanted feature A new feature for the syntax or library. good first issue Perfect for new contributors labels Aug 19, 2023
@juntyr
Copy link
Member

juntyr commented Aug 21, 2023

I think especially with #479, I'm now convinced that this is a good idea to ensure that values can roundtrip. I'll see if I can work on this tomorrow.

As I'm on it, I should also check the integer and float parsing rules to ensure that both accept _ in the correct places, such that number parsing should just be:

  • identify the byte span of the number, as before
  • check after this span for a number type suffix
  • check if i128/u128 is allowed
  • give a nice error if it's a float literal but with an int prefix
  • give a nice error if it's a negative literal but an unsigned integer
  • use existing parsing logic, but constrain the types to the specified ones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature for the syntax or library. good first issue Perfect for new contributors help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants