std.io
Reader/Writer, std streams, FixedBuf, NullWriter, printing; no allocation
IoError
Section titled “IoError”pub IoError :: errors { write_failed, short_write, read_failed, end_of_stream, buffer_full,}write_failed: The underlying write call returned zero bytesshort_write: A partial write where a full write was requiredread_failed: The underlying read call failedend_of_stream: The reader reached the end of available databuffer_full: A FixedBuf ran out of space mid-write
Writer
Section titled “Writer”pub Writer :: interface { write :: fn(self: *Self, data: []const u8) -> usize ! IoError; flush :: fn(self: *Self) -> void ! IoError;}byte sink; use *Writer for dynamic dispatch
Reader
Section titled “Reader”pub Reader :: interface { read :: fn(self: *Self, buf: []u8) -> usize ! IoError;}byte source; read gives <= buf.len, may give fewer; 0 only at end (or for an empty buf)
Stdout
Section titled “Stdout”pub Stdout :: struct { marker: u8,}Stderr
Section titled “Stderr”pub Stderr :: struct { marker: u8,}stdout
Section titled “stdout”pub stdout :: fn() -> Stdoutstderr
Section titled “stderr”pub stderr :: fn() -> Stderrpub Stdin :: struct { marker: u8,}stdin as a Reader; read gives 0 at end (closed pipe, Ctrl+Z / Ctrl+D)
pub stdin :: fn() -> StdinSliceReader
Section titled “SliceReader”pub SliceReader :: struct { rest: []const u8,}rest: the bytes not read yet
slice_reader
Section titled “slice_reader”pub slice_reader :: fn(data: []const u8) -> SliceReaderpub copy :: fn(dst: *Writer, src: *Reader, buf: []u8) -> u64 ! IoErrorcopy all of src to dst via buf; returns bytes copied
FixedBuf
Section titled “FixedBuf”pub FixedBuf :: struct { data: [256]u8, pos: usize,}fixed_buf
Section titled “fixed_buf”pub fixed_buf :: fn() -> FixedBufbuf_len
Section titled “buf_len”pub buf_len :: fn(self: *FixedBuf) -> usizebytes written
buf_remaining
Section titled “buf_remaining”pub buf_remaining :: fn(self: *FixedBuf) -> usizebytes left
buf_reset
Section titled “buf_reset”pub buf_reset :: fn(self: *FixedBuf)clear for reuse
buf_flush_stdout
Section titled “buf_flush_stdout”pub buf_flush_stdout :: fn(self: *FixedBuf) -> usize ! IoErrorflush to stdout in one syscall
buf_flush_stderr
Section titled “buf_flush_stderr”pub buf_flush_stderr :: fn(self: *FixedBuf) -> usize ! IoErrorflush to stderr in one syscall
buf_flush
Section titled “buf_flush”pub buf_flush :: fn(self: *FixedBuf, sink: *Writer) -> usize ! IoErrorflush to any *Writer in one call
NullWriter
Section titled “NullWriter”pub NullWriter :: struct { count: usize,}null_writer
Section titled “null_writer”pub null_writer :: fn() -> NullWriternull_reset
Section titled “null_reset”pub null_reset :: fn(self: *NullWriter)zero the byte count
write_all
Section titled “write_all”pub write_all :: fn(self: *Writer, data: []const u8) -> usize ! IoErrorall of data or fail; a short write is short_write
write_line
Section titled “write_line”pub write_line :: fn(self: *Writer, data: []const u8) -> usize ! IoErrordata then “\n”
write_char
Section titled “write_char”pub write_char :: fn(self: *Writer, ch: u8) -> usize ! IoErrorwrite_repeat
Section titled “write_repeat”pub write_repeat :: fn(self: *Writer, ch: u8, count: usize) -> usize ! IoErrorcount copies of ch
write_bool
Section titled “write_bool”pub write_bool :: fn(self: *Writer, value: bool) -> usize ! IoErrorwrite_u64
Section titled “write_u64”pub write_u64 :: fn(self: *Writer, value: u64) -> usize ! IoErrordecimal; recursion depth <= 20
write_i64
Section titled “write_i64”pub write_i64 :: fn(self: *Writer, value: i64) -> usize ! IoErrordecimal; i64 min is safe: abs via -(n+1)+1, no overflow
write_hex_byte
Section titled “write_hex_byte”pub write_hex_byte :: fn(self: *Writer, value: u8) -> usize ! IoErrortwo lowercase hex digits
write_hex_u64
Section titled “write_hex_u64”pub write_hex_u64 :: fn(self: *Writer, value: u64) -> usize ! IoErrorlowercase hex, no leading zeros, no prefix; recursion depth <= 16
write_hex_u64_full
Section titled “write_hex_u64_full”pub write_hex_u64_full :: fn(self: *Writer, value: u64) -> usize ! IoErrorexactly 16 lowercase hex digits, no prefix
pub print :: fn(f: Format) -> usize ! IoErrorprintln
Section titled “println”pub println :: fn(f: Format) -> usize ! IoErroreprint
Section titled “eprint”pub eprint :: fn(f: Format) -> usize ! IoErroreprintln
Section titled “eprintln”pub eprintln :: fn(f: Format) -> usize ! IoErrorprint_u64
Section titled “print_u64”pub print_u64 :: fn(value: u64) -> usize ! IoErrorprint_i64
Section titled “print_i64”pub print_i64 :: fn(value: i64) -> usize ! IoErrorprint_hex_u64
Section titled “print_hex_u64”pub print_hex_u64 :: fn(value: u64) -> usize ! IoErrorprint_bool
Section titled “print_bool”pub print_bool :: fn(value: bool) -> usize ! IoErroreprint_u64
Section titled “eprint_u64”pub eprint_u64 :: fn(value: u64) -> usize ! IoErroreprint_i64
Section titled “eprint_i64”pub eprint_i64 :: fn(value: i64) -> usize ! IoErrorwrite_fmt
Section titled “write_fmt”pub write_fmt :: fn(self: *Writer, f: Format) -> usize ! IoErrorwrite f through a 512-byte buffer, so a line is one write
write_fmt_line
Section titled “write_fmt_line”pub write_fmt_line :: fn(self: *Writer, f: Format) -> usize ! IoErrorwrite_fmt + newline
show_value
Section titled “show_value”pub show_value :: fn(f: *Formatter, d: *const u8, id: usize, ti: TypeInfo, spec: []const u8)Formatter.show for std.io: the value at d (type ti, type id id) per spec