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.Writer.VTable
pub const VTable = struct

Fields

drain: *const fn (w: *Writer, data: []const []const u8, splat: usize) Error!usize

Sends bytes to the logical sink. A write will only be sent here if it could not fit into buffer, or during a flush operation.

buffer[0..end] is consumed first, followed by each slice of data in order. Elements of data may alias each other but may not alias buffer.

This function modifies Writer.end and Writer.buffer in an implementation-defined manner.

data.len must be nonzero.

The last element of data is repeated as necessary so that it is written splat number of times, which may be zero.

This function may not be called if the data to be written could have been stored in buffer instead, including when the amount of data to be written is zero and the buffer capacity is zero.

Number of bytes consumed from data is returned, excluding bytes from buffer.

Number of bytes returned may be zero, which does not indicate stream end. A subsequent call may return nonzero, or signal end of stream via error.WriteFailed.

sendFile: *const fn ( w: *Writer, file_reader: *File.Reader, /// Maximum amount of bytes to read from the file. Implementations may /// assume that the file size does not exceed this amount. Data from /// `buffer` does not count towards this limit. limit: Limit, ) FileError!usize = unimplementedSendFile

Copies contents from an open file to the logical sink. buffer[0..end] is consumed first, followed by limit bytes from file_reader.

Number of bytes logically written is returned. This excludes bytes from buffer because they have already been logically written. Number of bytes consumed from buffer are tracked by modifying end.

Number of bytes returned may be zero, which does not indicate stream end. A subsequent call may return nonzero, or signal end of stream via error.WriteFailed. Caller may check file_reader state (File.Reader.atEnd) to disambiguate between a zero-length read or write, and whether the file reached the end.

error.Unimplemented indicates the callee cannot offer a more efficient implementation than the caller performing its own reads.

flush: *const fn (w: *Writer) Error!void = defaultFlush

Consumes all remaining buffer.

The default flush implementation calls drain repeatedly until end is zero, however it is legal for implementations to manage end differently. For instance, Allocating flush is a no-op.

There may be subsequent calls to drain and sendFile after a flush operation.

rebase: *const fn (w: *Writer, preserve: usize, capacity: usize) Error!void = defaultRebase

Ensures capacity more bytes can be buffered without rebasing.

The most recent preserve bytes must remain buffered.

Only called when capacity bytes cannot fit into the unused capacity of buffer.

File

Io/Writer.zig:20
20
21
22
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
pub const VTable = struct {
    /// Sends bytes to the logical sink. A write will only be sent here if it
    /// could not fit into `buffer`, or during a `flush` operation.
    ///
    /// `buffer[0..end]` is consumed first, followed by each slice of `data` in
    /// order. Elements of `data` may alias each other but may not alias
    /// `buffer`.
    ///
    /// This function modifies `Writer.end` and `Writer.buffer` in an
    /// implementation-defined manner.
    ///
    /// `data.len` must be nonzero.
    ///
    /// The last element of `data` is repeated as necessary so that it is
    /// written `splat` number of times, which may be zero.
    ///
    /// This function may not be called if the data to be written could have
    /// been stored in `buffer` instead, including when the amount of data to
    /// be written is zero and the buffer capacity is zero.
    ///
    /// Number of bytes consumed from `data` is returned, excluding bytes from
    /// `buffer`.
    ///
    /// Number of bytes returned may be zero, which does not indicate stream
    /// end. A subsequent call may return nonzero, or signal end of stream via
    /// `error.WriteFailed`.
    drain: *const fn (w: *Writer, data: []const []const u8, splat: usize) Error!usize,

    /// Copies contents from an open file to the logical sink. `buffer[0..end]`
    /// is consumed first, followed by `limit` bytes from `file_reader`.
    ///
    /// Number of bytes logically written is returned. This excludes bytes from
    /// `buffer` because they have already been logically written. Number of
    /// bytes consumed from `buffer` are tracked by modifying `end`.
    ///
    /// Number of bytes returned may be zero, which does not indicate stream
    /// end. A subsequent call may return nonzero, or signal end of stream via
    /// `error.WriteFailed`. Caller may check `file_reader` state
    /// (`File.Reader.atEnd`) to disambiguate between a zero-length read or
    /// write, and whether the file reached the end.
    ///
    /// `error.Unimplemented` indicates the callee cannot offer a more
    /// efficient implementation than the caller performing its own reads.
    sendFile: *const fn (
        w: *Writer,
        file_reader: *File.Reader,
        /// Maximum amount of bytes to read from the file. Implementations may
        /// assume that the file size does not exceed this amount. Data from
        /// `buffer` does not count towards this limit.
        limit: Limit,
    ) FileError!usize = unimplementedSendFile,

    /// Consumes all remaining buffer.
    ///
    /// The default flush implementation calls drain repeatedly until `end` is
    /// zero, however it is legal for implementations to manage `end`
    /// differently. For instance, `Allocating` flush is a no-op.
    ///
    /// There may be subsequent calls to `drain` and `sendFile` after a `flush`
    /// operation.
    flush: *const fn (w: *Writer) Error!void = defaultFlush,

    /// Ensures `capacity` more bytes can be buffered without rebasing.
    ///
    /// The most recent `preserve` bytes must remain buffered.
    ///
    /// Only called when `capacity` bytes cannot fit into the unused capacity
    /// of `buffer`.
    rebase: *const fn (w: *Writer, preserve: usize, capacity: usize) Error!void = defaultRebase,
}