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.

consume

Removes the first n bytes from buffer by shifting buffer contents, returning how many bytes are left after consuming the entire buffer, or zero if the entire buffer was not consumed.

Useful for VTable.drain function implementations to implement partial drains.

Writer.consume
pub fn consume(w: *Writer, n: usize) usize

File

lib/std/Io/Writer.zig:2311

Code

pub fn consume(w: *Writer, n: usize) usize {
    if (n < w.end) {
        const remaining = w.buffer[n..w.end];
        @memmove(w.buffer[0..remaining.len], remaining);
        w.end = remaining.len;
        return 0;
    }
    defer w.end = 0;
    return n - w.end;
}