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.
fnmarkSecret(ptr: anytype, comptimeaction: enum { classify, declassify }) void {
constt = @typeInfo(@TypeOf(ptr));
if (t != .pointer) @compileError("Pointer expected - Found: " ++ @typeName(@TypeOf(ptr)));
constp = t.pointer;
if (p.attrs.@"allowzero") @compileError("A nullable pointer is always assumed to leak information via side channels");
constchild = @typeInfo(p.child);
switch (child) {
.void, .null, .comptime_int, .comptime_float => return,
.pointer => {
if (child.pointer.size == .Slice) {
@compileError("Found pointer to pointer. If the intent was to pass a slice, maybe remove the leading & in the function call");
}
@compileError("A pointer value is always assumed leak information via side channels");
},
else => {
constmem8: *const [@sizeOf(@TypeOf(ptr.*))]u8 = @ptrCast(@constCast(ptr));
if (action == .classify) {
std.valgrind.memcheck.makeMemUndefined(mem8);
} else {
std.valgrind.memcheck.makeMemDefined(mem8);
}
},
}
}