On this page
article
Chapter 16: Quick Reference
Operators
-- arithmetic
+ - * / % -- checked (panic on overflow)
+% -% *% -- wrapping
+| -| *| -- saturating
-- logical (word)
and or not xor
-- bitwise (symbol)
& | ~ ^ << >>
-- comparison
= != < > <= >= -- = is equality (not ==)
-- assignment
:= -- reassignment
+= -= *= /= etc. -- compound
-- type operators
is as as? -- type check, cast, safe cast
-- error/optional
try -- propagate error
? -- propagate None
orelse -- provide default
catch -- handle error
-- pointer
.* -- dereference
& -- address-of
Common Patterns
-- defer cleanup
var x = try acquire();
defer x.release();
-- errdefer (error path only)
var buf = try alloc.alloc(u8, n);
errdefer alloc.free(buf);
-- optional unwrap
if maybe -> val { use(val); }
var n = maybe orelse 0;
-- error propagation
var n = try riskyOp();
var n = riskyOp() catch 0;
var n = riskyOp() catch wrap;
-- comptime type check
inline if #implements(T, Clone) { ... }
inline for field in #typeInfo(T).fields { ... }
Import Paths
-- files are namespaces, . is field access
const std = import("std");
const List = std.collections.List;
const Io = import("std/io").Io;
-- re-export from your module
pub const HashMap = import("std/collections/hashmap").HashMap;