DoxigAlpha

ArgsTuple

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 }

Source

Implementation

#
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);
}