Type Function ArgsTuple [src]
For a given function type, returns a tuple type which fields will
correspond to the argument types.
Examples:
ArgsTuple(fn () void) ⇒ tuple { }
ArgsTuple(fn (a: u32) u32) ⇒ tuple { u32 }
ArgsTuple(fn (a: u32, b: f16) noreturn) ⇒ tuple { u32, f16 }
Prototype
pub fn ArgsTuple(comptime Function: type) type
Parameters
Function: type
Example
test ArgsTuple {
TupleTester.assertTuple(.{}, ArgsTuple(fn () void));
TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));
TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));
TupleTester.assertTuple(.{ u32, f16, []const u8, void }, ArgsTuple(fn (a: u32, b: f16, c: []const u8, void) noreturn));
TupleTester.assertTuple(.{u32}, ArgsTuple(fn (comptime a: u32) []const u8));
}
Source
pub fn ArgsTuple(comptime Function: type) type {
const info = @typeInfo(Function);
if (info != .@"fn")
@compileError("ArgsTuple expects a function type");
const function_info = info.@"fn";
if (function_info.is_var_args)
@compileError("Cannot create ArgsTuple for variadic function");
var argument_field_list: [function_info.params.len]type = undefined;
inline for (function_info.params, 0..) |arg, i| {
const T = arg.type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter");
argument_field_list[i] = T;
}
return CreateUniqueTuple(argument_field_list.len, argument_field_list);
}