Skip to content
Xen / docs

Search documentation

English · v0.1.0-demo.2

Type to search the documentation.

    한국어
    Xen / reference v0.1.0-demo.2

    std.io

    APIs documented for this release.

    use std.io;
    APIReturn value
    std.io.read_stdin()Result<String, IoError>; read until the end of input
    std.io.write_stdout(text: String), std.io.write_stderr(text: String)Result<Int, IoError>; bytes written
    std.io.describe_error(error: IoError)Human-readable error text

    read_stdin waits for end of input and holds the entire input in memory. Write functions return bytes written. A complete pipeline example follows.

    use std.io as io;
    use std.string as text;
    fn main() {
    let contents = match io.read_stdin() {
    Result.Ok(value) => value,
    Result.Err(error) => { panic(io.describe_error(error)); },
    };
    let words = text.split_ascii_whitespace(contents);
    for index in 0..words.len() {
    println(words.get(index));
    }
    }
    Terminal window
    $ printf 'one two\nthree\n' | xen run stdin_words.xen
    one
    two
    three

    The IoError variants are InvalidPath, Open(Int), Read(Int), Write(Int), WriteZero, Close(Int), Metadata(Int), Directory(Int), Cwd(Int), and InvalidDirectoryEntry. Use describe_error for a message to display.