authorgravatar for yujiri@disroot.orgYujiri <yujiri@disroot.org> 2022-08-29 15:50:42+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 13:46:58-07:00
logd8970de510d2452f73251f6a2b663968dcd4ad37
tree586ca2db36a4599f38db51b4e21bc71c2a7a104f
parent72199c26b90aa8b31f2a70a5c7b3b8d443feef0b

Add docstrings to some functions in std.meta


1 files changed, 4 insertions(+), 2 deletions(-)

lib/std/meta.zig+4-2
......@@ -105,6 +105,7 @@ test "std.meta.isTag for Tagged Unions" {
105105 try testing.expect(!isTag(flt, "int"));
106106}
107107
108/// Returns the variant of an enum type, `T`, which is named `str`, or `null` if no such variant exists.
108109pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
109110 // Using ComptimeStringMap here is more performant, but it will start to take too
110111 // long to compile if the enum is large enough, due to the current limits of comptime
......@@ -192,6 +193,7 @@ test "std.meta.alignment" {
192193 try testing.expect(alignment(fn () align(128) void) == 128);
193194}
194195
196/// Given a parameterized type (array, vector, pointer, optional), returns the "child type".
195197pub fn Child(comptime T: type) type {
196198 return switch (@typeInfo(T)) {
197199 .Array => |info| info.child,
......@@ -210,7 +212,7 @@ test "std.meta.Child" {
210212 try testing.expect(Child(Vector(2, u8)) == u8);
211213}
212214
213/// Given a "memory span" type, returns the "element type".
215/// Given a "memory span" type (array, slice, vector, or pointer to such), returns the "element type".
214216pub fn Elem(comptime T: type) type {
215217 switch (@typeInfo(T)) {
216218 .Array => |info| return info.child,
......@@ -505,7 +507,6 @@ test "std.meta.declarationInfo" {
505507 try testing.expect(!info.is_pub);
506508 }
507509}
508
509510pub fn fields(comptime T: type) switch (@typeInfo(T)) {
510511 .Struct => []const Type.StructField,
511512 .Union => []const Type.UnionField,
......@@ -652,6 +653,7 @@ test "std.meta.tags" {
652653 try testing.expectEqual(E2.A, e2_tags[0]);
653654}
654655
656/// Returns an enum with a variant named after each field of `T`.
655657pub fn FieldEnum(comptime T: type) type {
656658 const field_infos = fields(T);
657659