Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRecursive and unsized enums #1151
Comments
This comment has been minimized.
This comment has been minimized.
|
I think this is a really cool idea, if it can work (I don't momentarily see any reason why it couldn't, but I haven't thought very hard). Reminds me a bit of serialization formats where you have a flat stream of bytes with tags to indicate what comes next. |
This comment has been minimized.
This comment has been minimized.
|
It could be a little tricky to define how to construct one of these. A similar instance of the same problem exists today: it’s valid to to define a struct whose last field is a non-type-parameter unsized type… struct Dst {
x: [u8],
}…but it’s basically impossible to construct one of these, because there’s no |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@P1start you would only allow it in an in-place context ( |
This comment has been minimized.
This comment has been minimized.
|
I think this is really a cool idea, and is needed for the sake of consistency. |
nrc
added
the
T-lang
label
Aug 29, 2016
This comment has been minimized.
This comment has been minimized.
serprex
commented
Nov 8, 2016
|
A useful extension of this is that an unsized enum which is non recursive could also be useful for taking up less space (consider |
This comment has been minimized.
This comment has been minimized.
tupshin
commented
Jan 7, 2017
|
I'll just weigh in in favor of this given my internals question where I unexpectedly ran into this same limitation. |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Jan 7, 2017
•
|
There are discussions elsewhere about doing
so that if Assuming the trait fields RFC, there is a version with nicer borrowing semantics
where We can maybe do the recursive unwrapping these describe using this approach like
except with lifetimes and All this looks less ergonomic of course, but you could maybe fix that with macros somehow. And it's definitely something lower-level developers run into frequently. I donno if this approach might place less nicely with future schemes for type-level numerics though. |
tomaka commentedJun 5, 2015
It is currently forbidden to have this enum, because it is recursive:
However in theory we could accept it by making
Sequenceunsized.