Araq helped me with this, turns out you need static[int] to get around "Error:
cannot instantiate"
This works:
type PackedString[N: static[int]] = array[N, char]
proc pack[N](str: string): PackedString[N] =
if str.len > result.len:
raise newException(ValueError, "Can't pack " & $str.len & " string into
" & $result.len)
for i in 0..<result.len:
if i >= str.len:
result[i] = char(0)
else:
result[i] = str[i]
# example struct
type Test = object
x: int32
y: int32
name: PackedString[16] #array[16, char]
life: float32
var test: Test
test.name = pack[16]("supernamething")
echo sizeOf(Test)