Skip to content

Commit

Permalink
Handle generic function in Signature
Browse files Browse the repository at this point in the history
  • Loading branch information
steeve committed Aug 6, 2024
1 parent c415c47 commit e2416ff
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/coro.zig
Original file line number Diff line number Diff line change
Expand Up @@ -266,26 +266,29 @@ const CoroT = struct {
YieldT: type = void,
InjectT: type = void,
ArgsT: type,
_ReturnT: type,

// If the function this signature represents is compile-time known,
// it can be held here.
func_ptr: ?type = null,

fn init(comptime Func: anytype, comptime options: CoroT.Options) @This() {
const FuncT = if (@TypeOf(Func) == type) Func else @TypeOf(Func);
const ArgsT = options.ArgsT orelse ArgsTuple(FuncT);
return .{
.Func = FuncT,
.YieldT = options.YieldT,
.InjectT = options.InjectT,
.ArgsT = options.ArgsT orelse ArgsTuple(FuncT),
.ArgsT = ArgsT,
.func_ptr = if (@TypeOf(Func) == type) null else struct {
const val = Func;
},
._ReturnT = @TypeOf(@call(.auto, Func, @as(ArgsT, undefined))),
};
}

pub fn ReturnT(comptime self: @This()) type {
return @typeInfo(self.Func).Fn.return_type.?;
return self._ReturnT;
}
};

Expand Down

0 comments on commit e2416ff

Please sign in to comment.