Module std::io
Byte input by the line. Standard input is read through the root's Stdin (a prelude effect,
beside Stdout and Stderr): Stdin.read(&mut b) copies the next bytes there are into b,
and Stdin.read_line(&mut b) those up to and including the next \n, each answering the
count, 0 at the end of the input. read_line and read_to_end append to a Buf<u8>
instead (hence with Stdin, Alloc); the root buffers standard input, so a line is no system
call. A socket or a file has no such buffer: a LineReader is one, for any source of
bytes. The input is bytes, as given: a line need not be UTF-8, and String::from_utf8
validates one. In the simulated world (the library default, the playground, weir explore
and weir test) standard input is empty; a test scripts it with std::sim::SimStdin.
Source: std/io.weir; committed interface: std/io.iface. Index
- fn
read_line: Appends the next line of standard input toout, its\nincluded (the last line of an input that does not end in one has none):Ok(true)when there was a line,Ok(false)at the end of the input,Err(errno)when a read failed. - fn
read_to_end: Appends the rest of standard input toout: the count appended, orErr(errno)when a read failed (what came before it stays appended). - const
LINE_BUFFER: The bytes aLineReaderholds. - struct
LineReader: A buffer between a source of bytes and its reader, so that reading by the line costs one read of the source perLINE_BUFFERbytes and not one per line or per byte. One reader serves one source: the bytes it holds are that source's next ones.
fn read_line
pub fn read_line(out: &mut Buf<u8>) -> Result<Bool, Int> with Stdin, Alloc
Appends the next line of standard input to out, its \n included (the last line of an
input that does not end in one has none): Ok(true) when there was a line, Ok(false) at
the end of the input, Err(errno) when a read failed.
Committed interface (std/io.iface):
bound Stdin: Stdin any
bound Alloc: Alloc any
may diverge
aborts: Alloc.alloc
scheduling point: Stdin not quiet
writes through out: {cap, data, len} and its shape
fn read_to_end
pub fn read_to_end(out: &mut Buf<u8>) -> Result<usize, Int> with Stdin, Alloc
Appends the rest of standard input to out: the count appended, or Err(errno) when a read
failed (what came before it stays appended).
Committed interface (std/io.iface):
bound Stdin: Stdin any
bound Alloc: Alloc any
may diverge
aborts: Alloc.alloc
scheduling point: Stdin not quiet
writes through out: {cap, data, len} and its shape
const LINE_BUFFER
pub const LINE_BUFFER: usize = 4096;
The bytes a LineReader holds.
struct LineReader
pub struct LineReader {
/* private fields */
}
A buffer between a source of bytes and its reader, so that reading by the line costs one
read of the source per LINE_BUFFER bytes and not one per line or per byte. One reader
serves one source: the bytes it holds are that source's next ones.
impl LineReader
method new
pub fn new() -> LineReader
A reader holding no bytes.
Committed interface (std/io.iface): the signature alone.
method read_line
pub fn read_line(
&mut self,
out: &mut Buf<u8>,
fill: fn(&mut [u8]) -> Result<usize, Int>,
) -> Result<Bool, Int> with Alloc
Appends the source's next line to out, its \n included (the last line of an input
that does not end in one has none), as read_line does for standard input: Ok(true)
when there was a line, Ok(false) at the end of the input, Err(errno) when a read
failed (what came before it stays appended). fill reads the source: it copies the next
bytes there are into the view it is given and answers their count, 0 at the end, as
|b| recv(&conn, b) and |b| Stdin.read(b) do. A line may be longer than the buffer,
and out grows by all of it: a fill that answers an error once it has brought more
than a peer may send is the bound.
Committed interface (std/io.iface):
bound Alloc: Alloc any
may diverge
aborts: Alloc.alloc
writes through self: {at, buf, end}
writes through out: {cap, data, len} and its shape
callback fill: envelope {A, S}; pinned: Alloc not portable; holds self, out, fill