Function declarationInfo [src]
Prototype
pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.Declaration
Parameters
T: type
decl_name: []const u8
Example
test declarationInfo {
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 infos = comptime [_]Type.Declaration{
declarationInfo(E1, "a"),
declarationInfo(S1, "a"),
declarationInfo(U1, "a"),
};
inline for (infos) |info| {
try testing.expect(comptime mem.eql(u8, info.name, "a"));
}
}
Source
pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.Declaration {
inline for (comptime declarations(T)) |decl| {
if (comptime mem.eql(u8, decl.name, decl_name))
return decl;
}
@compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'");
}