Skip to content

Commit

Permalink
Moved type check outside loop
Browse files Browse the repository at this point in the history
  • Loading branch information
permutationlock committed Nov 24, 2023
1 parent 49a503a commit 403edee
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/zimpl.zig
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const Type = @import("std").builtin.Type;

pub fn Impl(comptime T: type, comptime Ifc: fn (type) type) type {
switch (@typeInfo(Unwrap(T))) {
.Struct, .Union, .Enum, .Opaque => {},
else => return Ifc(T),
}
const ifc = @typeInfo(Ifc(T)).Struct.fields;
var fields = @as(*const [ifc.len]Type.StructField, @ptrCast(ifc.ptr)).*;
for (&fields) |*field| {
switch (@typeInfo(Unwrap(T))) {
inline else => |info| if (@hasField(@TypeOf(info), "decls")) {
if (@hasDecl(Unwrap(T), field.name)) {
const decl = @field(Unwrap(T), field.name);
field.*.default_value = &@as(field.type, decl);
}
},
if (@hasDecl(Unwrap(T), field.name)) {
const decl = @field(Unwrap(T), field.name);
field.*.default_value = &@as(field.type, decl);
}
}
return @Type(Type{ .Struct = .{
Expand Down

0 comments on commit 403edee

Please sign in to comment.