kw if
Reserved keyword — policy (§13.4)
The list of words: §1.4
Syntax
Rule = ( "allow" | "deny" ) ( "*" | RTarget { "," RTarget } ) ( "if" | "unless" ) Expr ;MockArm = Ident "(" [ Patterns ] ")" [ "if" Expr ] "=>" MockSeq ;If = "if" ( Expr | "let" Pattern "=" Expr ) Block [ "else" ( If | Block ) ] ;Match = "match" Expr "{" { Pattern [ "if" Expr ] "=>" Expr ( "," | NL ) } "}" ;Grammar: App. A
Defined in
- 5.4 Conditions — There is no ternary operator.
- 14.2 Dynamic configuration — dynamic Name { …
- 4.3 Construction and constructors — Literal. T{ f1: e1, f2, ..base }
- 6.5 Errors — There are no exceptions.
- 1.4 Keywords — Reserved (cannot be used as names)
- 3.5 Unions and optionals — A | B — an anonymous union.
- 5.1 General rules — Almost everything is an expression
- 13.4 Authorisation and policies — The subject of a policy
Examples
let kind = if n < 0 { "neg" } else if n == 0 { "zero" } else { "pos" }
if let User{ role: .Admin, name, .. } = u { greet(name) }
if x is Receipt { save(x) } // x is narrowed to Receiptdynamic Limits {
rps: u32 = DEFAULT_RPS
newSearch: Flag = Flag.off
}
let l = Limits.get()
if current > l.rps.get() { throttle() }
for await v in l.rps.changes() { limiter.set(v) }
if l.newSearch.on(for: ctx.caller) { newSearch(q) } else { oldSearch(q) }Related diagnostics
bad-init, missing-field, must-close, positional-literal, sealed-literal, fail-type, question-context, unhandled-error, type-mismatch, not-assignable, data-rights, missing-policy, unknown-policy-target