op ->
->
Precedence: −1 Associativity: left
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 — + - * / % ** +% -% % +| -| | & | ^ ~ << >> && || !
- 9.5 User-defined serialisers — Level 1 — representation through another type (Repr), acts in all formats and in schemas
- 8.4 Chains — A chain links asynchronous steps so that either the whole chain is executed or the first unhandled error is returned.
- 10.6 Pipelines — A pipeline is a linear chain of steps, each of which runs on its own node; data is passed from node to node directly, the caller receives on
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
@repr(i64)
data Money { minor: i64 }
impl Repr<i64> for Money {
fn toRepr() -> i64 => minor
static fn fromRepr(v: i64) -> Money | DecodeError => Money{ minor: v }
}— 9.5 User-defined serialisers
Related diagnostics
chained-comparison, not-callable, not-overloadable, operator-decl, range-not-iterable, invalid-char, schema-attr, it-outside-chain, pipeline-idempotency, respond-twice, respond-type, unknown-role