import std::io; # A constant a trait asks for, read through a type parameter it bounds, is a # constant wherever one stands: a fixed array's length, in a signature or a # field too, a constant type argument, or a `const`, each instance giving it # the type's own. So are the constants of `array` and `pointer`, and a local # `const` worked out from a constant parameter. trait sized { const bytes: u64; } const i32::bytes: u64 = 4; const i64::bytes: u64 = 8; struct buffer { var items: T[N]; } struct holder where T: sized { var raw: u8[T::bytes]; var held: buffer; } def flag(): u64 { return B ? 1u : 0u; } def count(): u64 { return N; } def raw(x: T): u8[T::bytes] where T: sized { var out: u8[T::bytes]; return out; } def padded(x: T): buffer where T: sized { var out: buffer; return out; } def local(x: T): u64 where T: sized { const n: u64 = T::bytes * 3; var arr: u8[n]; return arr.length + count::(); } def doubled(): u64 where T: array { return size_of::(); } def writes(): u64 where T: pointer { return flag::(); } def scaled(): u64 { const m: u64 = N + 1; var arr: u8[m]; return arr.length; } def main(): void { var h: holder; println($"{raw(3 as i32).length} {raw(3).length} {padded(3 as i32).items.length} {h.raw.length} {h.held.items.length}"); println($"{local(3 as i32)} {local(3)} {doubled::()} {writes::<*mut u8>()} {writes::<*u8>()} {scaled::<4>()}"); }