Nested tagged unions

I would keep enum for quantities:

    const Quantity = enum {
        dist, // short for 'distance'
        time, // you can place your philosophy of what "time" is here :-)
        mass, 
    };

    const UnitOf = union(Quantity) { // better than just union(enum)
        dist: enum {mm, m, km},
        time: enum {s, min, h},
        mass: enum {mg, g, kg},
    };