Io Package
Unstable API
The package is under active development and its API is not yet stable. Names, signatures, and behavior may change between releases, and this documentation will be updated to match.
The package provides standard input and output — a Print and a PrintLine for every primitive type and for text, and a ReadLine that reads a line back.
Module: Io
Source: github.com/rux-lang/Io
Every function talks to the process's own standard streams: the standard handles on Windows and macOS, and the standard file descriptors on Linux and illumos. Nothing is buffered on the way — a Print is a write.
import Io::{ Print, PrintLine, ReadLine };
func Main() -> int {
Print("What is your name? ");
var name = ReadLine();
PrintLine("Hello, {}!", name);
name.Free();
return 0;
}Installation
rux add Io
rux installPlatform support
Implemented on illumos, Linux, macOS, and Windows. BSD is not implemented yet — the package has no BSD backend, so a program that prints or reads there does not build for that target.
Values as text
A value is turned into text by Format, which this package is built on, and it is the same text you would get from ToString: a bool prints as true or false rather than as 0 or 1, a char prints as its UTF-8 bytes, and a float is rendered to the digits its type carries with the trailing zeros dropped, so 0.1 prints as 0.1.
Both Print and PrintLine also take a format string, where each {} takes the next argument in order and {{ and }} write a literal brace:
PrintLine("{} of {} done", 3, 10); // 3 of 10 done
PrintLine("{{{}}}", "braced"); // {braced}The arguments are Stringable, so a type of your own goes into a {} the moment it implements that interface. Any String a placeholder allocates on the way is freed for you.
Widths and aliases
bool is an alias for bool8, char for char32, and float for float64, so a call on an alias reaches the overload for the sized type it names. int and uint are types of their own rather than names for int64 and uint64, and have overloads of their own.
Ownership
Print and PrintLine own nothing: a String passed to either is only read, and it is still yours to Free afterwards.
ReadLine is the other way around. The String it returns is a fresh allocation the caller owns and passes to String::Free exactly once, on the terms Text sets out — including the line that came back empty.
Functions
Output
| Function | Description |
|---|---|
Print | Write a value to standard output. |
PrintLine | The same, followed by a newline. |
Input
| Function | Description |
|---|---|
ReadLine | Read standard input through the next newline, as a String. |