Struct

std::io::Input!

source
struct Input! { ... }

A buffered reader of standard input or a file: lines (read_line), chunks (read, read_exact) and the rest (read_to_end). Standard input's is the one reader of it while it lives (see stdin). Its end, read_to_end or finish, gives standard input back or closes the file.

Methods

method read_linesource

fn read_line(&self) -> Result[Option[Buffer!], Error] { ... }

The next line, without its newline: None at the end of input, when no byte is left to read; an empty line is Some of an empty buffer, and a last line with no newline is still a line. A read error is returned, and the bytes of the line read before it are lost with it. It reads ahead, 64 KiB at a time.

method read_to_endsource

fn read_to_end(self) -> Result[Buffer!, Error] { ... }

The rest of the input, read to its end, the bytes read ahead first, and the reading ended: standard input is given back, for the next stdin, and a file is closed. A file's is read into a buffer sized up front by the file's size, so a regular file is read without growing it; reading goes on to EOF whatever the size said, so a file that grows or shrinks meanwhile is read as it is, and a pipe, device or socket is read until it ends. A directory is EISDIR. A failure to read, or else to close the file, is the error: a read error takes precedence, and a failed close frees what was read.

method readsource

fn read(&self, &buf: Buffer!, max: usize) -> Result[usize, Error] { ... }

Reads at most max bytes, appending them to buf: how many, which is 0 at the end of the input (and for a max of 0). Bytes read ahead come first, and while there are any, no more are read; else it is one read(2). Fewer than max is no sign of the end (a pipe gives what it has); read until it returns 0. A failed read is the error, with buf as it was.

method read_exactsource

fn read_exact(&self, &buf: Buffer!, size: usize) -> Result[usize, Error] { ... }

Reads size bytes, appending them to buf, again after each short read: how many, which is fewer only at the end of the input. Bytes read ahead come first. A failed read is the error, even when some bytes were appended before it; they stay in buf.

method finishsource

fn finish(self) -> Result[Buffer!, Error] { ... }

Ends the reading: the bytes read ahead and not returned yet, which no later reader sees. Standard input is given back, for the next stdin; a file is closed, and a failed close(2) is the error, with those bytes freed.