I am currently building a library (https://github.com/phillord/horned-owl) where I have the need to express “at least two, but any number” of items.
Currently, my struct is specified like so:
That is any number of classes. This allows me to construct illegal data compared to the spec which says “at least two”.
The best solution I have so far is to change the type to:
DisjointUnion(Class, Class, Vec<Class>)
(that is two classes and the rest, rather like Java does variadic calls).
or alternatively create a new Vec wrapper that does all in one:
pub struct VecTwoPlus(A, A, Vec<A>) DisjointUnion(Vec2plus<Class>)
I can’t see anyway in Rust to make VecTwoPlus generic over the number, but I don’t think this is a problem since in this case, the number is always two.
Am I missing something simpler? Or has anyone done it already?