|
|
|
|
|
by weberc2
3505 days ago
|
|
> such as wasting memory Granted, but I'll happily trade a few bytes of stack for zero allocs in many cases. > rather than benefiting from overlapping storage ala Rust enums or C tagged unions Of course, but we don't have those in Go, do we? > as well as losing type safety Tagged structs are not meaningfully less type safe than interfaces. > one has to manually remember which (groups of) fields correspond to which tag values Use an enum for the tag: https://play.golang.org/p/LI2Bh231W3 |
|
Of course they are. What if you read from or write to the wrong field?
> Use an enum for the tag
Your example has one contained type per variant. In Rust it is common to have an enum like
Naming tags for something like this would be hard. Some of the fields would be shared between variants. Some would not.