Zig 0.17.0-dev (Split by item)

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 library itself.

decl_fields_fallible

main.decl_fields_fallible
fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index

File

lib/docs/wasm/main.zig:387

Code

fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index {
    const decl = decl_index.get();
    const ast = decl.file.get_ast();

    switch (decl.categorize()) {
        .type_function => {
            // If the type function returns a reference to another type function, get the fields from there
            if (decl.get_type_fn_return_type_fn()) |function_decl| {
                return decl_fields_fallible(function_decl);
            }
            // If the type function returns a container, such as a `struct`, read that container's fields
            if (decl.get_type_fn_return_expr()) |return_expr| {
                switch (ast.nodeTag(return_expr)) {
                    .container_decl, .container_decl_trailing, .container_decl_two, .container_decl_two_trailing, .container_decl_arg, .container_decl_arg_trailing => {
                        return ast_decl_fields_fallible(ast, return_expr);
                    },
                    else => {},
                }
            }
            return &.{};
        },
        else => {
            const value_node = decl.value_node() orelse return &.{};
            return ast_decl_fields_fallible(ast, value_node);
        },
    }
}