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 Function
inlinefnintFromValue(x: anytype) u64 {
constT = @TypeOf(x);
returnswitch (@typeInfo(T)) {
.comptime_int => x,
.bool => @intFromBool(x),
.@"enum" => @backingInt(x),
else => @as(@Int(.unsigned, @bitSizeOf(T)), @bitCast(x)),
.int => |i| x: {
comptime {
if (i.signedness == .signed) {
@compileError("type does not have a continous range: " ++ @typeName(T));
}
// Reject types that don't have a fixed bitsize (esp. usize)// since they are not gauraunteed to fit in a u64 across targets.//// std.mem.indexOfScalar is not used to avoid backward branches// and preserve the eval branch quota.if (T == usizeorT == c_charorT == c_ushortorT == c_uintorT == c_ulongorT == c_ulonglong)
{
@compileError("type does not have a fixed bitsize: " ++ @typeName(T));
}
}
break :xx;
},
.comptime_float,
.float,
=> @compileError("type does not have a continous range: " ++ @typeName(T)),
.pointer => @compileError("type does not have a fixed bitsize: " ++ @typeName(T)),
};
}