Module

std::io

source

Input and output through the standard streams and files.

Process I/O over the POSIX read/write/open/close/fstat calls: printing to standard output (print) and standard error (eprint), any Printable value: print("done\n"), print(f"{n} files\n"); the owning descriptor type File!; Output!, the one buffered writer, of standard output, standard error or a file (File!::output); Input!, the one buffered reader, of standard input (stdin) or a file (File!::input); and Error, the error of every operating-system call of the library. Paths are any byte view (c_string); std::fs works with them whole.

Types

ErrorAn I/O error: the errno of the system call that failed, or EIO (5) for a failure the system did not report itself (a write that made no progress).
ErrorKindWhat kind of failure an Error is, for code that handles some kinds: the errnos a portable program tells apart, whatever their numbers on the host.
Source!What an Input! reads: standard input, which it holds until its end (read_to_end or finish), or a file it owns and closes then.
Input!A buffered reader of standard input or a file: lines (read_line), chunks (read, read_exact) and the rest (read_to_end).
File!Owns one open file descriptor.
Sink!Where an Output! writes: standard output or error, which it does not own and never closes, or a file it owns and closes on finish.
Output!Buffered writer to standard output, standard error or a file.

Functions

c_stringA path, name or argument for C: the bytes of a view, read through the capability that permits it, followed by a NUL, in a buffer the caller frees once the call is made.
write_allWrites ptr[0..len) to fd, retrying partial writes.
printPrints x to standard output (Printable): print("done\n"), print(f"{n} files\n").
eprintPrints x to standard error, as print does to standard output.
read_intoReads at most max bytes from fd, with one read(2), appending them to buf: how many, which is 0 at the end of the input (and for a max of 0, which reads nothing).
read_to_end_fromReads fd to EOF, appending to b and returning it.
stdinStandard input, held by the Input! returned until its read_to_end or finish, or EBUSY while another Input! holds it.
rest_ofbuf[start..) in a buffer of its own, with room for room bytes more; buf is freed.
stdoutA buffered writer for standard output.
stderrA buffered writer for standard error.

Instances

Format[Error, W]An error formats as its description and its errno: No such file or directory (error 2).
Printable[Error, W]An error prints as it formats: No such file or directory (error 2).
Writer[Output!]Output as a writer: bytes gather and are written 4 KiB at a time.

Function declarations

fn c_stringsource

forall C, S where ReadBytes[C, S], Copy[S].
fn c_string(&cx: C, bytes: S) -> Buffer! { ... }

A path, name or argument for C: the bytes of a view, read through the capability that permits it, followed by a NUL, in a buffer the caller frees once the call is made. The C functions (libc) that take one also take its length, and fail with EINVAL when the bytes hold a NUL of their own, which C would read as the end.

fn write_allsource

unsafe fn write_all(fd: i32, ptr: *u8, len: usize) -> Result[(), Error] { ... }

Writes ptr[0..len) to fd, retrying partial writes. Caller: ptr[0..len) is readable, and fd is a descriptor the caller may write: standard output or error, or one a File! it holds owns.

fn printsource

forall T where Printable[T, Output!].
fn print(x: T) -> Result[(), Error] { ... }

Prints x to standard output (Printable): print("done\n"), print(f"{n} files\n"). Returns an I/O error on failure.

fn eprintsource

forall T where Printable[T, Output!].
fn eprint(x: T) -> Result[(), Error] { ... }

Prints x to standard error, as print does to standard output.

fn read_intosource

unsafe fn read_into(fd: i32, &buf: Buffer!, max: usize) -> Result[usize, Error] { ... }

Reads at most max bytes from fd, with one read(2), appending them to buf: how many, which is 0 at the end of the input (and for a max of 0, which reads nothing). Fewer than max is no sign of the end: a pipe gives what it has. The error of a failed read, with buf as it was. Caller: fd is a descriptor the caller may read: stdin, or one a File! it holds owns.

fn read_to_end_fromsource

unsafe fn read_to_end_from(fd: i32, b: Buffer!) -> Result[Buffer!, Error] { ... }

Reads fd to EOF, appending to b and returning it. Each read fills the room b has, and a full b grows first, by at least 4096 bytes and at least doubling, so a b made with room for all the input and one byte more reads it without growing. A read error frees what was read and is returned: it never looks like the end of the input. Caller: fd is a descriptor the caller may read, as for read_into.

fn stdinsource

fn stdin() -> Result[Input!, Error] { ... }

Standard input, held by the Input! returned until its read_to_end or finish, or EBUSY while another Input! holds it.

fn rest_ofsource

fn rest_of(buf: Buffer!, start: usize, room: usize) -> Buffer! { ... }

buf[start..) in a buffer of its own, with room for room bytes more; buf is freed.

fn stdoutsource

fn stdout() -> Output! { ... }

A buffered writer for standard output.

fn stderrsource

fn stderr() -> Output! { ... }

A buffered writer for standard error.

Instance declarations

instance Format[Error, W]source

forall W where Writer[W].
instance Format[Error, W] { ... }

An error formats as its description and its errno: No such file or directory (error 2).

instance Printable[Error, W]source

forall W where Writer[W].
instance Printable[Error, W] { ... }

An error prints as it formats: No such file or directory (error 2).

instance Writer[Output!]source

instance Writer[Output!] { ... }

Output as a writer: bytes gather and are written 4 KiB at a time.