| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| | 2 | const extras = @import("extras"); |
| 2 | | 3 | |
| 3 | pub const Value = union(enum) { | 4 | pub const Value = union(enum) { |
| 4 | Object: []Member, | 5 | Object: []Member, |
| ... | @@ -34,6 +35,14 @@ pub const Value = union(enum) { | ... | @@ -34,6 +35,14 @@ pub const Value = union(enum) { |
| 34 | return self.fetch_inner(query, 0); | 35 | return self.fetch_inner(query, 0); |
| 35 | } | 36 | } |
| 36 | | 37 | |
| | 38 | pub fn getT(self: Value, query: anytype, comptime ty: std.meta.FieldEnum(Value)) ?extras.FieldType(Value, ty) { |
| | 39 | if (self.get(query)) |val| { |
| | 40 | if (val == .Null) return null; |
| | 41 | return @field(val, @tagName(ty)); |
| | 42 | } |
| | 43 | return null; |
| | 44 | } |
| | 45 | |
| 37 | fn fetch_inner(self: Value, query: anytype, comptime n: usize) ?Value { | 46 | fn fetch_inner(self: Value, query: anytype, comptime n: usize) ?Value { |
| 38 | if (query.len == n) { | 47 | if (query.len == n) { |
| 39 | return self; | 48 | return self; |