Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Type Function

CheckAllAllocationFailuresExtraArgs

Private Type Function
std.testing.CheckAllAllocationFailuresExtraArgs
fn CheckAllAllocationFailuresExtraArgs(comptime TestFn: type) type

File

testing.zig:1191
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
fn CheckAllAllocationFailuresExtraArgs(comptime TestFn: type) type {
    switch (@typeInfo(@typeInfo(TestFn).@"fn".return_type.?)) {
        .error_union => |info| {
            if (info.payload != void) {
                @compileError("Return type must be !void");
            }
        },
        else => @compileError("Return type must be !void"),
    }

    const ArgsTuple = std.meta.ArgsTuple(TestFn);

    const field_types = @typeInfo(ArgsTuple).@"struct".field_types;
    if (field_types.len == 0 or field_types[0] != std.mem.Allocator) {
        @compileError("The provided function must have an " ++ @typeName(std.mem.Allocator) ++ " as its first argument");
    }

    var extra_args: [field_types.len - 1]type = undefined;
    for (&extra_args, field_types[1..]) |*arg, field_type| {
        arg.* = field_type;
    }

    return @Tuple(&extra_args);
}