std::io
I/O
Standard output, error printing, and structured I/O error types.
All types and functions live under the Io namespace.
Printing
| Function | Stream | Newline | Accepts |
|---|---|---|---|
Io::print |
stdout | No | String |
Io::println |
stdout | Yes | String, str |
Io::eprint |
stderr | No | String |
Io::eprintln |
stderr | Yes | String, str |
println and eprintln are overloaded for both String and str:
Stringoverload: the value is consumed (moved), dropped after printing, and writesmessage.length()bytes.stroverload: writes the C string directly, no heap allocation.
print and eprint only accept String (no str overload).
String overloads write message.length() bytes. str overloads remain
NUL-terminated C-string writes and may stop at the first interior NUL.
str overloads remain NUL-terminated C-string writes.
Error Types
| Type | Source file | Description |
|---|---|---|
Io::ErrorKind |
error.ign | Category of the I/O error (8 variants) |
Io::IoError |
error.ign | Full error: kind + raw errno + strerror message |
Example
import Io from "std::io";
import LibC from "std::libc";
import String from "std::string";
function main(): i32 {
Io::println(String::create("hello, world!"));
// I/O error from a failed syscall
let fd: i32 = LibC::File::open("/nonexistent", LibC::File::O_RDONLY);
if (fd == -1) {
let err: Io::IoError = Io::IoError::lastError();
// err.kind == Io::ErrorKind::NOT_FOUND
// err.message == "No such file or directory"
return 1;
}
return 0;
}
namespace IoStandard I/O namespace.
println and eprintln have overloads for both String and str.
String overloads consume/move the value. str overloads forward the
C string directly.
Functions
function eprint(message: String): voidPrints message to stderr without a trailing newline.
Arguments
message- The String to print (consumed/moved).
Example
import Io from "std::io";
import String from "std::string";
Io::eprint(String::create("warning: "));
Io::eprintln(String::create("low disk space"));
function eprintln(message: str): voidPrints a str message to stderr followed by a newline (\n).
Writes the C string directly via write(2), no heap allocation.
Arguments
message- Thestrliteral or slice to print.
function eprintln(message: str): voidPrints a str message to stderr followed by a newline (\n).
Writes the C string directly via write(2), no heap allocation.
Arguments
message- Thestrliteral or slice to print.
function print(message: String): voidPrints message to stdout without a trailing newline.
Useful for building up output incrementally or printing prompts.
Arguments
message- The String to print (consumed/moved).
Example
import Io from "std::io";
import String from "std::string";
Io::print(String::create("Enter name: "));
function println(message: str): voidPrints a str message to stdout followed by a newline (\n).
Writes the C string directly via write(2), no heap allocation.
Arguments
message- Thestrliteral or slice to print.
function println(message: str): voidPrints a str message to stdout followed by a newline (\n).
Writes the C string directly via write(2), no heap allocation.
Arguments
message- Thestrliteral or slice to print.
Functions
function __vectorStringMonomorphizationRoots(): voidKeeps Vector<String> monomorphizations reachable for std I/O builds.
Some std APIs return or manipulate Vector<String> only through code paths
that may be optimized away in small programs. This internal root forces the
compiler to instantiate clear/drop paths used by linked std modules.