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

Expose number of variants when serializing enum #663

Closed
dtolnay opened this issue Jan 3, 2017 · 1 comment
Closed

Expose number of variants when serializing enum #663

dtolnay opened this issue Jan 3, 2017 · 1 comment
Assignees
Labels

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 3, 2017

From IRC:

<cmr> Hm, this seems problematic. My serializer can't keep unbounded state, but I want to encode enum variant tags with the minimum amount of bytes necessary, using the same representation Rust does ideally.
<cmr> The obvious approach of using a stack of recent total-number-of-variants is out, but I don't see how else it's possible.
<cmr> (in fact, afaict, the serializer *never even has access* to that information, although the deserializer does.)
<cmr> in the form of the len of the variants arg to deserialize_enum

cc @cmr

@dtolnay
Copy link
Member Author

dtolnay commented Jan 19, 2017

@cmr I don't have the IRC logs but if I remember correctly, you realized that aiming for an encoding that is "at most as many bytes as Rust" was not feasible because of NonZero-related optimizations such as for Option<&T>, not to mention rust-lang/rfcs#1230. For just minimizing number of bytes, a variable-length encoding seems like it would be a better approach. The vast majority of enums will use 1 byte.

I am inclined to not make this change, rather than complicating the Serializer interface for this use case. What do you think?

@dtolnay dtolnay removed this from the v0.9.0 milestone Jan 21, 2017
@dtolnay dtolnay closed this as completed Jan 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants