| author | |
| committer | |
| log | b7767eb834084adc9db94b9ed961aaa2756fc018 |
| tree | 3c342592d962fe7417f8c79291437d6d564e617f |
| parent | 68ec54f386d387c5dd3f9dc4f0b5e14be6ae10a6 |
| signature |
2 files changed, 7 insertions(+), 5 deletions(-)
lib/std/json.zig+2-2| ... | @@ -2077,7 +2077,7 @@ pub const Parser = struct { | ... | @@ -2077,7 +2077,7 @@ pub const Parser = struct { |
| 2077 | } | 2077 | } |
| 2078 | } | 2078 | } |
| 2079 | 2079 | ||
| 2080 | fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayloadType(Token, Token.String), input: []const u8, i: usize) !Value { | 2080 | fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayload(Token, Token.String), input: []const u8, i: usize) !Value { |
| 2081 | const slice = s.slice(input, i); | 2081 | const slice = s.slice(input, i); |
| 2082 | switch (s.escapes) { | 2082 | switch (s.escapes) { |
| 2083 | .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice }, | 2083 | .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice }, |
| ... | @@ -2090,7 +2090,7 @@ pub const Parser = struct { | ... | @@ -2090,7 +2090,7 @@ pub const Parser = struct { |
| 2090 | } | 2090 | } |
| 2091 | } | 2091 | } |
| 2092 | 2092 | ||
| 2093 | fn parseNumber(p: *Parser, n: std.meta.TagPayloadType(Token, Token.Number), input: []const u8, i: usize) !Value { | 2093 | fn parseNumber(p: *Parser, n: std.meta.TagPayload(Token, Token.Number), input: []const u8, i: usize) !Value { |
| 2094 | return if (n.is_integer) | 2094 | return if (n.is_integer) |
| 2095 | Value{ .Integer = try std.fmt.parseInt(i64, n.slice(input, i), 10) } | 2095 | Value{ .Integer = try std.fmt.parseInt(i64, n.slice(input, i), 10) } |
| 2096 | else | 2096 | else |
lib/std/meta.zig+5-3| ... | @@ -649,9 +649,11 @@ test "std.meta.activeTag" { | ... | @@ -649,9 +649,11 @@ test "std.meta.activeTag" { |
| 649 | testing.expect(activeTag(u) == UE.Float); | 649 | testing.expect(activeTag(u) == UE.Float); |
| 650 | } | 650 | } |
| 651 | 651 | ||
| 652 | const TagPayloadType = TagPayload; | ||
| 653 | |||
| 652 | ///Given a tagged union type, and an enum, return the type of the union | 654 | ///Given a tagged union type, and an enum, return the type of the union |
| 653 | /// field corresponding to the enum tag. | 655 | /// field corresponding to the enum tag. |
| 654 | pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type { | 656 | pub fn TagPayload(comptime U: type, tag: @TagType(U)) type { |
| 655 | testing.expect(trait.is(.Union)(U)); | 657 | testing.expect(trait.is(.Union)(U)); |
| 656 | 658 | ||
| 657 | const info = @typeInfo(U).Union; | 659 | const info = @typeInfo(U).Union; |
| ... | @@ -665,14 +667,14 @@ pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type { | ... | @@ -665,14 +667,14 @@ pub fn TagPayloadType(comptime U: type, tag: @TagType(U)) type { |
| 665 | unreachable; | 667 | unreachable; |
| 666 | } | 668 | } |
| 667 | 669 | ||
| 668 | test "std.meta.TagPayloadType" { | 670 | test "std.meta.TagPayload" { |
| 669 | const Event = union(enum) { | 671 | const Event = union(enum) { |
| 670 | Moved: struct { | 672 | Moved: struct { |
| 671 | from: i32, | 673 | from: i32, |
| 672 | to: i32, | 674 | to: i32, |
| 673 | }, | 675 | }, |
| 674 | }; | 676 | }; |
| 675 | const MovedEvent = TagPayloadType(Event, Event.Moved); | 677 | const MovedEvent = TagPayload(Event, Event.Moved); |
| 676 | var e: Event = undefined; | 678 | var e: Event = undefined; |
| 677 | testing.expect(MovedEvent == @TypeOf(e.Moved)); | 679 | testing.expect(MovedEvent == @TypeOf(e.Moved)); |
| 678 | } | 680 | } |