3. Types
| Type | Values | Notes |
|---|---|---|
i8 i16 i32 i64 |
signed integers of 8 to 64 bits | section 7 |
u8 u16 u32 u64 |
unsigned integers of 8 to 64 bits | section 7 |
usize |
unsigned, the size of a pointer | section 7 |
f32 f64 |
IEEE 754 floating point, 32 and 64 bits | section 7 |
bool |
true, false |
|
str |
immutable byte strings | section 8 |
void |
none | only as a function result (E108 elsewhere) |
struct Name |
records of named fields | section 9 |
enum Name |
one of a fixed set of names | section 10 |
union(enum) Name |
one member, maybe with a payload | section 10 |
[N]T |
N values of type T, N >= 1 | value type; section 11 |
[]T |
a view of consecutive T, read-only unless inout |
parameters, local slices and function results; section 11 |
!T |
a T or an error | section 13 |
anyerror |
an error: error.Name |
compared with ==, switched on, named with @errorName; section 13 |
?T |
a T or null |
section 13 |
*T |
the address of a T, or null |
using one needs allow unsafe; section 18 |
fn(T, U) R |
a function | section 19 |
type |
a type, at compile time only | comptime parameters; section 14 |
Io |
the io capability | received by main, passed down; section 17 |
Allocator |
the alloc capability | received by main, passed down; section 17 |
Fs |
the fs capability | received by main, passed down; section 17 |
Net |
the net capability | received by main, passed down; section 17 |
Threads |
the thread capability | received by main, passed down; section 17 |
Args |
the args capability | received by main, passed down; section 17 |
Buf(T) |
an owned heap buffer of T | moved, not copied; section 21 |
MultiArrayList(T) |
an owned list of the struct T, one column per field | moved, not copied; section 21 |
Every type that has runtime values, except slices and buffers, is a value type:
assignment, passing and returning copy the value (void and type have
no runtime values). There are no implicit conversions. Every
operator and every assignment, argument and return requires exactly the
expected type (E103), with these exceptions: a T fits where !T or
?T is expected, error.X fits any !T, and null any ?T. Integers are not booleans: if (1)
is an error.
// error: E103
uses io
fn main(io: Io) void {
if (1) { io.print(1) }
}