op {
{
Defined in
- 5.2 Precedence and associativity — Precedence and associativity
- 5.3 Overloading and user-defined operators — Overloading built-in operators — op declarations in impl
- 1.6 Operators and delimiters — + - * / % ** +% -% % +| -| | & | ^ ~ << >> && || !
- 4.3 Construction and constructors — Literal. T{ f1: e1, f2, ..base }
- 1.5 Literals — Rules:
- 5.6 Loops — for accepts Iterable<T> (including iter<T>, collections, ranges); for await accepts Streamable<T>.
Examples
impl Vec3 {
static op +(a: Vec3, b: Vec3) -> Vec3 => Vec3(a.x + b.x, a.y + b.y, a.z + b.z)
static op *(v: Vec3, k: f32) -> Vec3 => Vec3(v.x * k, v.y * k, v.z * k)
static op -(v: Vec3) -> Vec3 => v * -1.0
op [](i: usize) -> f32 { … } // read by index
var op [](i: usize) -> &var f32 { … } // write by index
op ()(t: f32) -> Vec3 { … } // call as a function
static op <=>(a: Vec3, b: Vec3) -> Ordering { … }
op as Vec4 => Vec4(x, y, z, 1.0)
}— 5.3 Overloading and user-defined operators
for u in users { … }
for (i, u) in users.enumerate() { … }
for i in 0..n where i % 2 == 0 { … } // filter
for await msg in input { … } // stream<T>
while cond { … }
while let x? = queue.pop() { … }
loop { if done { break result } } // loop is an expression
'outer: for a in xs { for b in ys { if a == b { break 'outer } } }Related diagnostics
chained-comparison, not-callable, not-overloadable, operator-decl, range-not-iterable, invalid-char, bad-init, missing-field, must-close, positional-literal, sealed-literal, bad-format-spec, invalid-char-literal, invalid-date