-
Notifications
You must be signed in to change notification settings - Fork 18
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
Tagged Union/Associated Data in enum support #80
Comments
thanks for the proposal. let's clarify this a little.
|
I just think of it like this:
So using the example above:
This is nice because the current Rust enum implementation won't be able to optimize the discriminator size (it almost always takes one byte at the least), so we can pack the whole thing into one byte rather than having align_up(8 + 6) = 16 bits = 2 bytes. One byte savings could be significant! |
https://alic.dev/blog/dense-enums Just saw this on HN today. Could be useful. |
This is like a normal Rust
enum
except we have a known limited choice, and this means we have to add a discriminator field and the subsequent bits. This is very useful to represent bit fields inside a C union.Final size of the enum is (discriminator bits + max(content of each enum)). Examples coming soon.
This means we have a u8 field because we have a u2 header/discriminator + max(all enum trailing content) = u6 so u8. This is indicated by the dominant size of Squirrel. All others will have their unused bits zero-extended.
The text was updated successfully, but these errors were encountered: