Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Public Struct

VTable

Public Struct
std.Io.Reader.VTable
pub const VTable = struct

Fields

stream: *const fn (r: *Reader, w: *Writer, limit: Limit) StreamError!usize

Writes bytes from the internally tracked logical position to w.

Returns the number of bytes written, which will be at minimum 0 and at most limit. The number returned, including zero, does not indicate end of stream.

The reader's internal logical seek position moves forward in accordance with the number of bytes returned from this function.

Implementations are encouraged to utilize mandatory minimum buffer sizes combined with short reads (returning a value less than limit) in order to minimize complexity.

Although this function is usually called when buffer is empty, it is also called when it needs to be filled more due to the API user requesting contiguous memory. In either case, the existing buffer data should be ignored; new data written to w.

In addition to, or instead of writing to w, the implementation may choose to store data in buffer, modifying seek and end accordingly. Implementations are encouraged to take advantage of this if it simplifies the logic.

discard: *const fn (r: *Reader, limit: Limit) Error!usize = defaultDiscard

Consumes bytes from the internally tracked stream position without providing access to them.

Returns the number of bytes discarded, which will be at minimum 0 and at most limit. The number of bytes returned, including zero, does not indicate end of stream.

The reader's internal logical seek position moves forward in accordance with the number of bytes returned from this function.

Implementations are encouraged to utilize mandatory minimum buffer sizes combined with short reads (returning a value less than limit) in order to minimize complexity.

The default implementation is is based on calling stream, borrowing buffer to construct a temporary Writer and ignoring the written data.

This function is only called when buffer is empty.

readVec: *const fn (r: *Reader, data: [][]u8) Error!usize = defaultReadVec

Returns number of bytes written to data.

data must have nonzero length. data[0] may have zero length, in which case the implementation must write to Reader.buffer.

data may not contain an alias to Reader.buffer.

data is mutable because the implementation may temporarily modify the fields in order to handle partial reads. Implementations must restore the original value before returning.

Implementations may ignore data, writing directly to Reader.buffer, modifying seek and end accordingly, and returning 0 from this function. Implementations are encouraged to take advantage of this if it simplifies the logic.

The default implementation calls stream with either data[0] or Reader.buffer, whichever is bigger.

rebase: *const fn (r: *Reader, capacity: usize) RebaseError!void = defaultRebase

Ensures capacity data can be buffered without rebasing.

Asserts capacity is within buffer capacity, or that the stream ends within capacity bytes.

Only called when capacity cannot be satisfied by unused capacity of buffer.

The default implementation moves buffered data to the start of buffer, setting seek to zero, and cannot fail.

File

Io/Reader.zig:23
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
pub const VTable = struct {
    /// Writes bytes from the internally tracked logical position to `w`.
    ///
    /// Returns the number of bytes written, which will be at minimum `0` and
    /// at most `limit`. The number returned, including zero, does not indicate
    /// end of stream.
    ///
    /// The reader's internal logical seek position moves forward in accordance
    /// with the number of bytes returned from this function.
    ///
    /// Implementations are encouraged to utilize mandatory minimum buffer
    /// sizes combined with short reads (returning a value less than `limit`)
    /// in order to minimize complexity.
    ///
    /// Although this function is usually called when `buffer` is empty, it is
    /// also called when it needs to be filled more due to the API user
    /// requesting contiguous memory. In either case, the existing buffer data
    /// should be ignored; new data written to `w`.
    ///
    /// In addition to, or instead of writing to `w`, the implementation may
    /// choose to store data in `buffer`, modifying `seek` and `end`
    /// accordingly. Implementations are encouraged to take advantage of
    /// this if it simplifies the logic.
    stream: *const fn (r: *Reader, w: *Writer, limit: Limit) StreamError!usize,

    /// Consumes bytes from the internally tracked stream position without
    /// providing access to them.
    ///
    /// Returns the number of bytes discarded, which will be at minimum `0` and
    /// at most `limit`. The number of bytes returned, including zero, does not
    /// indicate end of stream.
    ///
    /// The reader's internal logical seek position moves forward in accordance
    /// with the number of bytes returned from this function.
    ///
    /// Implementations are encouraged to utilize mandatory minimum buffer
    /// sizes combined with short reads (returning a value less than `limit`)
    /// in order to minimize complexity.
    ///
    /// The default implementation is is based on calling `stream`, borrowing
    /// `buffer` to construct a temporary `Writer` and ignoring the written
    /// data.
    ///
    /// This function is only called when `buffer` is empty.
    discard: *const fn (r: *Reader, limit: Limit) Error!usize = defaultDiscard,

    /// Returns number of bytes written to `data`.
    ///
    /// `data` must have nonzero length. `data[0]` may have zero length, in
    /// which case the implementation must write to `Reader.buffer`.
    ///
    /// `data` may not contain an alias to `Reader.buffer`.
    ///
    /// `data` is mutable because the implementation may temporarily modify the
    /// fields in order to handle partial reads. Implementations must restore
    /// the original value before returning.
    ///
    /// Implementations may ignore `data`, writing directly to `Reader.buffer`,
    /// modifying `seek` and `end` accordingly, and returning 0 from this
    /// function. Implementations are encouraged to take advantage of this if
    /// it simplifies the logic.
    ///
    /// The default implementation calls `stream` with either `data[0]` or
    /// `Reader.buffer`, whichever is bigger.
    readVec: *const fn (r: *Reader, data: [][]u8) Error!usize = defaultReadVec,

    /// Ensures `capacity` data can be buffered without rebasing.
    ///
    /// Asserts `capacity` is within buffer capacity, or that the stream ends
    /// within `capacity` bytes.
    ///
    /// Only called when `capacity` cannot be satisfied by unused capacity of
    /// `buffer`.
    ///
    /// The default implementation moves buffered data to the start of
    /// `buffer`, setting `seek` to zero, and cannot fail.
    rebase: *const fn (r: *Reader, capacity: usize) RebaseError!void = defaultRebase,
}