Xen / reference v0.1.0-demo.2
std.io
This topic is not available in the selected language or version. Showing the start of this section.
APIs documented for this release.
use std.io;| API | Return 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)); }}$ printf 'one two\nthree\n' | xen run stdin_words.xenonetwothreeThe 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.