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.

writeInt

mem.writeInt
pub inline fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).int.bits, 8)]u8, value: T, endian: Endian) void

File

lib/std/mem.zig:2024

Code

pub inline fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).int.bits, 8)]u8, value: T, endian: Endian) void {
    // Zig's logical bit order aligns with a little-endian byte array, so when writing in big-endian
    // we must `@byteSwap` the int before we `@bitCast` to an array.
    buffer.* = switch (endian) {
        .little => @bitCast(value),
        .big => @bitCast(@byteSwap(value)),
    };
}