Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Writing text with recoverable errors

write_stdout(text) borrows a string and writes exactly its contents, without a newline. Success returns the number of Unicode characters. An I/O error can follow a partial write, so retrying the whole string can duplicate output.

def main() -> Result[(), AllocError | IoError]:
    result = write_stdout("Hello!\n")
    print(result?)?
    Ok(())
Hello!
7

IoError.System(code) carries a native OS error code. Decoding, allocation, and stream-state errors have separate variants; the text I/O reference lists them all.