Quick Reference
| Concept | Syntax |
|---|---|
| Immutable binding | let x = 42 |
| Mutable binding | var x = 42 |
| Type annotation | let x: i32 = 42 |
| Function | fn name(a: i32): i32 { ... } |
| Generic function | fn name<T>(x: T): T { ... } |
| Struct | struct Name { field: Type } |
| Enum | enum Name { Variant(Type), Empty } |
| Match | match val { Variant(x) => { ... } } |
| If let | if let Variant(x) = val { ... } |
| Option shorthand | T? for Option<T> |
| Unwrap | expr! |
| Propagate | expr? |
| Default | expr ?? default |
| Array | [1, 2, 3] or [0; 100] |
| Vec | var v: Vec<i32> = Vec.new() |
| HashMap | var m: HashMap<K, V> = HashMap.new() |
| Heap | Heap(value), deref with *heaped |
| Reference param | fn f(x: &T) or fn f(x: &mut T) |
| Closure | (x: i32) => x * 2 |
| Import | from "path" import { A, B } |
| FFI | extern fn name(args): ret |
| Trait | trait Name { fn method(self: &Self): T } |
| Impl trait | impl Trait for Type { ... } |
| Impl methods | impl Type { ... } |
| Derive | @derive(Eq) |
| Generic bound | <T: Eq + Hash> |
| Cast | expr as Type |
| Embed file | embedFile("path") |
| JSON serialize | jsonStringify(struct_val) |
| String slice | s[start..end] |
| Number to string | n.toString() |
| Bitwise | & | ^ << >> ~ |
| Hex / binary literal | 0xFF, 0b1010 |