kw var
Reserved keyword
The list of words: §1.4
Syntax
Receiver = [ "var" | "move" | "static" ] ;ActorMember = { Attr } ( "var" Ident ":" Type "=" Expr | "dep" Ident ":" Type
| "msg" Ident "(" [ Params ] ")" [ "->" Type ] Block
| "on" ( "activate" | "passivate" ) Block ) ;AtomType = Path [ "<" TypeArgs ">" ] | "(" [ Type { "," Type } ] ")" | "[" Type [ ";" Expr ] "]"
| "&" [ "var" ] Type | "*" [ "var" ] Type | ( "frozen" | "sync" | "view" | "dyn" ) Type
| "fn" "(" [ Type { "," Type } ] ")" [ "->" Type ] [ Effects ] [ "escaping" ] | "never" ;Stmt = ( "let" | "var" ) Pattern [ ":" Type ] "=" Expr | Const | Place AssignOp Expr
| "defer" Expr | Expr ;Arg = [ Ident ":" ] Expr | "&" "var" Expr ;PatAlt = "_" | Literal | Literal ( ".." | "..=" ) Literal | [ "var" ] Ident [ "?" ]
| Type [ Ident ] | [ "." ] Path "(" [ Patterns ] ")" | Path "{" [ FieldPats ] [ ".." ] "}"
| "(" Patterns ")" | "[" [ Patterns ] [ ".." [ Ident ] ] "]" ;Grammar: App. A
Defined in
- 12.5 Sharded actors — The key is declared in the header (sharded by name
- 5.3 Overloading and user-defined operators — Overloading built-in operators — op declarations in impl
- 8.8 Local actors — Messages are processed strictly one at a time, in the order of arrival from each sender.
- 4.3 Construction and constructors — Literal. T{ f1: e1, f2, ..base }
- 4.5 impl and methods — Inside a method self and Self are available.
- 4.6 Interfaces — Interfaces are structural
- 5.1 General rules — Almost everything is an expression
- 6.7 Contracts — requires is checked on entry, ensures on exit (result is the return value, old(e) is the value of e on entry), invariant (§4.2) — after cons
Examples
@idle(ACCOUNT_IDLE)
actor Account sharded by id: AccountId {
var balance: Money = Money.zero()
@transient var hits: u64 = 0
on activate { log.debug("account {id} up") }
msg deposit(x: Money) { balance += x }
msg balance() -> Money { balance }
}
Account(id).deposit(amount)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
Related diagnostics
actor-not-hosted, not-callable, not-overloadable, operator-decl, range-not-iterable, actor-cycle, bad-init, missing-field, must-close, positional-literal, sealed-literal, impl-foreign-type, unknown-method, explicit-interface