Module std::io

Standard I/O operations.

Read from stdin and write to stdout or stderr.

Examples

import std.io;

fn main() {
    io.write("enter your name: ");
    let name = io.read_line() ?? "stranger";
    io.write("hello, ");
    io.write(name);
    io.write("\n");
}

Contents

Functions

Function read_line

pub fn read_line() -> Option<string>

Read one line from standard input.

The call waits without holding a scheduler thread, so other tasks keep running while input is silent. The trailing \n or \r\n is removed and invalid UTF-8 becomes U+FFFD. Returns None at end of input; a final line without a newline is still returned first. A read error traps.

Concurrent reads take lines in the order they started, each line going to exactly one of them. A read that a deadline or an enclosing scope cancels consumes nothing: the next read returns the line that was pending.

Function write

pub fn write(s: string)

Write a string to standard output without a trailing newline.

Function write_err

pub fn write_err(s: string)

Write a string to standard error without a trailing newline.

Function read_all

pub fn read_all() -> string

Read standard input to its end.

Waits like read_line, and a read error traps. Invalid UTF-8 becomes U+FFFD.