Output
print(value) writes one value to standard output, adds a newline, and returns Void.
It is available without an import. With import std;, you can also use std.print or std.io.print.
Each call takes exactly one argument. Combine values using string interpolation. There are no separator or terminator parameters.
Supported Types
Section titled “Supported Types”- UTF-8 byte slices (
UInt8[]&), including string literals. - Owned
String, which is consumed, or borrowedString&, which is preserved. Bool, signed and unsigned integers of all widths, andFloat16,Float32, andFloat64.- Borrowed custom values implementing
Formattable.
Floating-point output uses StringBuilder’s default six decimal places.
Borrow an existing string to keep using it:
Custom Formatting
Section titled “Custom Formatting”Implement Formattable and append text to the writable builder:
The borrowed value is preserved. Formattable is used by print; string interpolation uses
StringBuilder.append overloads and does not automatically call Formattable.format.
UTF-8 and Output Errors
Section titled “UTF-8 and Output Errors”String always contains valid UTF-8. When printing a byte slice, invalid sequences are replaced with
U+FFFD (�). Use String.from_utf8(bytes) when invalid input should produce a recoverable Utf8Error.
print panics if writing to standard output fails. For recoverable errors, raw bytes, or output without
a trailing newline, use std.io.stdout():