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.

defaultDiscard

Reader.defaultDiscard
pub fn defaultDiscard(r: *Reader, limit: Limit) Error!usize

File

lib/std/Io/Reader.zig:196

Code

pub fn defaultDiscard(r: *Reader, limit: Limit) Error!usize {
    assert(r.seek == r.end);
    r.seek = 0;
    r.end = 0;
    var d: Writer.Discarding = .init(r.buffer);
    var n = r.stream(&d.writer, limit) catch |err| switch (err) {
        error.WriteFailed => unreachable,
        error.ReadFailed, error.EndOfStream => |e| return e,
    };
    // If `stream` wrote to `r.buffer` without going through the writer,
    // we need to discard as much of the buffered data as possible.
    const remaining = @backingInt(limit) - n;
    const buffered_n_to_discard = @min(remaining, r.end - r.seek);
    n += buffered_n_to_discard;
    r.seek += buffered_n_to_discard;
    assert(n <= @backingInt(limit));
    return n;
}