niche value that operates on value level / context, for example number 0 of u8 (only 00000000 is valid), most of the proposed solution belongs to this category I believe, an example is Option and NonZero*
While at it we may also need to take care of large niche value space, like having every a niche value for every prime numbers, ideally these would all be compile-time only to avoid foot guns like reflection magic.
Maybe instead of trying to explain to the compiler where's the niche, there could be a run-time hook for packing/unpacking values from a custom enum representation?
I have no idea how it could look like syntax-wise, but the general idea is that you could implement some trait with "set enum to this value" and "get me current value of this enum" methods, and these could perform arbitrary work (maybe const) to pack the data however they want.
Hi, it surely wouldn't be just the enum right? What types is this approach intended to pack together? Niches seem all about making A * B type take less than sizeof(A) + sizeof(B) bytes, so what are A and B?
What I had in mind is a type like union U {A, B} plus a function that knows whether it's currently holding A or B, so you can have fn get_discriminant(&U) -> Discriminant<U> or maybe fn get_a(&U) -> Option<&A>.