std.meta: rename TagPayloadType to TagPayload

This commit is contained in:
Tadeo Kondrak 2021-01-11 10:58:33 -07:00 committed by Veikka Tuominen
parent 68ec54f386
commit b7767eb834
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
2 changed files with 7 additions and 5 deletions

View File

@ -2077,7 +2077,7 @@ pub const Parser = struct {
}
}
fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayloadType(Token, Token.String), input: []const u8, i: usize) !Value {
fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayload(Token, Token.String), input: []const u8, i: usize) !Value {
const slice = s.slice(input, i);
switch (s.escapes) {
.None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice },
@ -2090,7 +2090,7 @@ pub const Parser = struct {
}
}
fn parseNumber(p: *Parser, n: std.meta.TagPayloadType(Token, Token.Number), input: []const u8, i: usize) !Value {
fn parseNumber(p: *Parser, n: std.meta.TagPayload(Token, Token.Number), input: []const u8, i: usize) !Value {
return if (n.is_integer)
Value{ .Integer = try std.fmt.parseInt(i64, n.slice(input, i), 10) }
else

View File

@ -649,9 +649,11 @@ test "std.meta.activeTag" {
testing.expect(activeTag(u) == UE.Float);
}
const TagPayloadType = TagPayload;
///Given a tagged union type, and an enum, return the type of the union
/// field corresponding to the enum tag.
pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type {
pub fn TagPayload(comptime U: type, tag: @TagType(U)) type {
testing.expect(trait.is(.Union)(U));
const info = @typeInfo(U).Union;
@ -665,14 +667,14 @@ pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type {
unreachable;
}
test "std.meta.TagPayloadType" {
test "std.meta.TagPayload" {
const Event = union(enum) {
Moved: struct {
from: i32,
to: i32,
},
};
const MovedEvent = TagPayloadType(Event, Event.Moved);
const MovedEvent = TagPayload(Event, Event.Moved);
var e: Event = undefined;
testing.expect(MovedEvent == @TypeOf(e.Moved));
}