I'm building an implementation in Rust of an underlying serializable data model. The underlying model has atomic primitives and union types (among others).
I.e., imagine a set of name/value pairs, where, like JSON, the value can be an atom, an object, or a list of atoms or object or a union of atoms or objects.
Just atomic primitives would be pretty easy: build a enum of the underlying primitives (similar to what rustc_serializable or serde does with JSON primitives).
Dealing with arbitrary union types is a bit more tricky because I can't easily constrain the union to subsets of the primitives (refinement types?).
I can model the primitives, create an Atom or Value enum, and then create an enum for each union type, but that's a lot of indirection.
Is there a cleaner way of using Rust's type system that's obvious? I've thought, e.g., about a marker trait and using a generic type constrained only to marked items, but everything ends up looking super complex....