-
Reposting: https://cheats.rs/#memory-layout
> Does the value take up the same width regardless of state?
Yes. As the other commenter mentioned, it's the size of the largest variant (same as a union in C) + a tag (almost the same as an enum in C). In some cases, the compiler even manages to optimize out the tag.
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
I wish Go had (real) enums.
https://github.com/containerd/runwasi/blob/ba5ab5ada5a401762...
-
higher-kinded-lifecycle
A demonstration of an idea about how to represent the lifecycle of entities in Scala using higher-kinded types
Time to re-pimp my idea of doing this using a single type parameterised to reflect different states:
https://github.com/tim-group/higher-kinded-lifecycle/blob/ma...
-
> One thing Rust could really use are anonymous unions (A | B |C instead of E::A(A), E::B(B), E::C(C)). They are to enums what tuple types are to structs.
Ceylon had union types, which is the only place i've seen these: https://github.com/eclipse-archived/ceylon-lang.org/blob/mas...
Another thing Rust enums are missing is having each variant be a type. If you have an enum Shape with variants Circle, Rectangle, and Polygon, there is no way to write a function which only takes a Circle. So you end up defining a struct for each case, then making your enum a trivial wrapper round the three structs. You end up with Shape::Circle and Circle, which are different things, and writing code like c.0.radius to get at the fields. It's rather inelegant. So either variants should be types in their own right, or an enum should be defined as a composition of existing types.
-
I haven't been following this closely, so I looked it up and it looks like that's not going to happen for the foreseeable future unfortunately:
https://github.com/rust-lang/lang-team/issues/122
Kind of a shame, but wrapper types work well enough that I understand. It does look like if there was someone with enough resources to make it happen that they'd be receptive to it.