zigar.function.Generator(T).any(self) - chung-leong/zigar GitHub Wiki

Convert the generator to one whose yield() method accepts anyerror.

Example:

const std = @import("std");
const zigar = @import("zigar");

fn hello() error{InitFailed}!Iterator {
    return error.InitFailed;
}

const Iterator = struct {
    pub fn next(_: *@This()) error{NextFailed}!?i32 {
        return null;
    }
};

fn yield(_: ?*anyopaque, _: error{ InitFailed, NextFailed }!?i32) bool {
    return false;
}

comptime {
    const generator1: zigar.function.GeneratorOf(hello) = .{ .ptr = null, .callback = &yield };
    const generator2 = generator1.any();
    std.debug.assert(@TypeOf(generator2) == zigar.function.Generator(anyerror!?i32));
}

Arguments:

  • self: @This()

Return value:

Generator(anyerror!@typeInfo(T).error_union.payload)


Generator(T)