Function declarations [src]

Instead of this function, prefer to use e.g. @typeInfo(foo).@"struct".decls directly when you know what kind of type it is.

Prototype

pub fn declarations(comptime T: type) []const Type.Declaration

Parameters

T: type

Example

test declarations { const E1 = enum { A, pub fn a() void {} }; const S1 = struct { pub fn a() void {} }; const U1 = union { b: u8, pub fn a() void {} }; const O1 = opaque { pub fn a() void {} }; const decls = comptime [_][]const Type.Declaration{ declarations(E1), declarations(S1), declarations(U1), declarations(O1), }; inline for (decls) |decl| { try testing.expect(decl.len == 1); try testing.expect(comptime mem.eql(u8, decl[0].name, "a")); } }

Source

pub fn declarations(comptime T: type) []const Type.Declaration { return switch (@typeInfo(T)) { .@"struct" => |info| info.decls, .@"enum" => |info| info.decls, .@"union" => |info| info.decls, .@"opaque" => |info| info.decls, else => @compileError("Expected struct, enum, union, or opaque type, found '" ++ @typeName(T) ++ "'"), }; }