Function containerLayout [src]
Prototype
pub fn containerLayout(comptime T: type) Type.ContainerLayout
Example
test containerLayout {
const S1 = struct {};
const S2 = packed struct {};
const S3 = extern struct {};
const U1 = union {
a: u8,
};
const U2 = packed union {
a: u8,
};
const U3 = extern union {
a: u8,
};
try testing.expect(containerLayout(S1) == .auto);
try testing.expect(containerLayout(S2) == .@"packed");
try testing.expect(containerLayout(S3) == .@"extern");
try testing.expect(containerLayout(U1) == .auto);
try testing.expect(containerLayout(U2) == .@"packed");
try testing.expect(containerLayout(U3) == .@"extern");
}
Source
pub fn containerLayout(comptime T: type) Type.ContainerLayout {
return switch (@typeInfo(T)) {
.@"struct" => |info| info.layout,
.@"union" => |info| info.layout,
else => @compileError("expected struct or union type, found '" ++ @typeName(T) ++ "'"),
};
}