compile with zig master

I was actually anticipating a bit more stdlib breakage than this, so I
ended up just shimming it. Well, it works and also still works with
0.11.0, which is cool.
This commit is contained in:
torque 2023-11-23 18:37:10 -08:00
parent bd0d74ee6a
commit bd079b42d9
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk
2 changed files with 15 additions and 3 deletions

View File

@ -2,4 +2,11 @@
.name = "nice-data", .name = "nice-data",
.version = "0.1.0-pre", .version = "0.1.0-pre",
.dependencies = .{}, .dependencies = .{},
.paths = .{
"src",
"build.zig",
"build.zig.zon",
"license",
"readme.md",
},
} }

View File

@ -9,6 +9,11 @@
// CONDITIONS OF ANY KIND, either express or implied. // CONDITIONS OF ANY KIND, either express or implied.
const std = @import("std"); const std = @import("std");
const hasFn = if (@hasDecl(std.meta, "trait")) struct {
fn hasFn(comptime T: type, comptime name: []const u8) bool {
return std.meta.trait.hasFn(name)(T);
}
}.hasFn else std.meta.hasFn;
const Options = @import("../parser.zig").Options; const Options = @import("../parser.zig").Options;
@ -183,7 +188,7 @@ pub const Value = union(enum) {
} }
}, },
.Struct => |stt| { .Struct => |stt| {
if (comptime std.meta.trait.hasFn("deserializeNice")(T)) if (comptime hasFn(T, "deserializeNice"))
return T.deserializeNice(self, allocator, options); return T.deserializeNice(self, allocator, options);
if (stt.is_tuple) { if (stt.is_tuple) {
@ -244,7 +249,7 @@ pub const Value = union(enum) {
} }
}, },
.Enum => { .Enum => {
if (comptime std.meta.trait.hasFn("deserializeNice")(T)) if (comptime hasFn(T, "deserializeNice"))
return T.deserializeNice(self, allocator, options); return T.deserializeNice(self, allocator, options);
switch (self) { switch (self) {
@ -269,7 +274,7 @@ pub const Value = union(enum) {
} }
}, },
.Union => |unn| { .Union => |unn| {
if (comptime std.meta.trait.hasFn("deserializeNice")(T)) if (comptime hasFn(T, "deserializeNice"))
return T.deserializeNice(self, allocator, options); return T.deserializeNice(self, allocator, options);
if (unn.tag_type == null) @compileError("Cannot deserialize into untagged union " ++ @typeName(T)); if (unn.tag_type == null) @compileError("Cannot deserialize into untagged union " ++ @typeName(T));