Sentinel-terminated anything is mostly useful for interoperating with C APIs, since if you’re dealing with Zig APIs, then regular ol’ slices are better in most situations.
So the usefulness of non-0
sentinels would be dependent on the C APIs you are interacting with. For example, the Lua C API has some functions that take an array of luaL_Reg
structs where:
Any array of
luaL_Reg
must end with a sentinel entry in which bothname
andfunc
areNULL
.
In C, that looks like:
static const luaL_Reg luv_async_methods[] = {
{"send", luv_async_send},
{NULL, NULL}
};
In Zig, that could be expressed as something like (untested, might have the syntax here slightly wrong):
const luaL_RegTerminator = c.luaL_Reg{ .name = null, .func = null };
const luv_async_methods = [_:luaL_RegTerminator]c.luaL_Reg{
.{ .name = "send", .func = luv_async_send },
};