I think there must be an easier way. If a comptime int is available and I want to make a type that (only just) contains that, something like this seems a little inelegant(?)
const z: u32 = 130; // example; normally provided from outside
const T = switch(z) {
inline 0...15 => u4,
inline 16...32 => u5,
// ...
inline 128...255 => u8,
// ...
else => u32,
};
const y: T; // will be a u8 in this case