Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upEnums Size Option(Feature Request) #235
Comments
|
Yep, this is something that I've also wanted for a long time! I don't think that you could add it as an annotation to the struct, but it could certainly be a compile-time parameter to the bincode |
|
This could be extended to any std type that get serialized as (size,[u8]) as it is also really common for strings that contains usernames, passwords, dates, to be really short. The reason a mentioned a trait annotation is to allow certain fields to be serialized with a smaller index size and others with a greater one. If you think it is not viable then at least it should be done for Enums, as a discrete field type. |
|
I'd like to second this. Annotating the enum would be amazing! In almost all cases, a u8 would be sufficient |
|
Is it possible to know the number of variant of an enum ? If so it can be possible to choose the adapted integer type to encode the variant number. For example an The deserialiser knows the enum type that it is decoding therefore it knows the number of variant and so the integer type to decode. It is a breaking change to do this but it provides a perfect fit between correctness and data compression. |
|
Closing in favor of #319 |
It would be really convenient if I was able to configure the size of the Enum types index. I am currently writing an application that focus maximum compression of the data. The 4 byte size of the Enum size is more than the data size itself which in return makes me unable to use them. I think even at compile time or with an annotation I should be able to set the size of the Enum.
In my project no enum ever goes beyond the 512 discrete values barrier, so this is my suggestion: