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
safeTruncate
Private Function
std.array_hash_map.safeTruncate
fnsafeTruncate(comptimeT: type, val: anytype) T
@truncate fails if the target type is larger than the target value. This causes problems when one of the types is usize, which may be larger or smaller than u32 on different systems. This version of truncate is safe to use if either parameter has dynamic size, and will perform widening conversion when needed. Both arguments must have the same signedness.
Params
T: type
val
File
array_hash_map.zig:1573
15731574157515761577
fnsafeTruncate(comptimeT: type, val: anytype) T {
if (@bitSizeOf(T) >= @bitSizeOf(@TypeOf(val)))
returnval;
return@as(T, @truncate(val));
}
@truncate fails if the target type is larger than the target value. This causes problems when one of the types is usize, which may be larger or smaller than u32 on different systems. This version of truncate is safe to use if either parameter has dynamic size, and will perform widening conversion when needed. Both arguments must have the same signedness.