kw fn
Reserved keyword
The list of words: §1.4
Syntax
Fn = [ "comptime" [ "literal" ] | "unsafe" ] "fn" Ident [ Generics ] "(" [ Params ] ")"
[ "->" Type ] [ Effects ] [ Where ] { Contract } ( Block | "=>" Expr ) ;IMember = "embed" Type | "type" Ident [ "=" Type ] | Receiver "fn" Sig [ "=>" Expr | Block ] ;ImplMember = { Attr } [ Vis ] ( Receiver ( "fn" | "op" ) Sig ( Block | "=>" Expr )
| "override" "fn" Sig ( Block | "=>" Expr ) | "open" "fn" Sig ( Block | "=>" Expr )
| "init" Sig ( Block | "=>" Expr ) | "dep" Ident ":" Type | Rpc | Const ) ;AtomType = Path [ "<" TypeArgs ">" ] | "(" [ Type { "," Type } ] ")" | "[" Type [ ";" Expr ] "]"
| "&" [ "var" ] Type | "*" [ "var" ] Type | ( "frozen" | "sync" | "view" | "dyn" ) Type
| "fn" "(" [ Type { "," Type } ] ")" [ "->" Type ] [ Effects ] [ "escaping" ] | "never" ;Grammar: App. A
Defined in
- 9.5 User-defined serialisers — Level 1 — representation through another type (Repr), acts in all formats and in schemas
- 2.4 Entry points and start-up order — A program is a package that contains at least one of
- 4.5 impl and methods — Inside a method self and Self are available.
- 4.6 Interfaces — Interfaces are structural
- 4.3 Construction and constructors — Literal. T{ f1: e1, f2, ..base }
- 4.7 Embedding and overriding — There is no implementation inheritance.
- 4.8 Generics — Parameters: type parameters T, constant parameters const N
- 6.1 Function declaration — Without -> T the return type is () (for private functions with a body => e the type is inferred from e).
Examples
@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
pub(api) interface Storage {
fn get(k: str) -> bytes? io
var fn put(k: str, v: bytes) io
fn has(k: str) -> bool io => get(k) != none // a default method
}
interface ReadWrite { embed Reader; embed Writer }
interface Container<T> { type Item = T; fn items() -> iter<T> }
@explicit interface Persistent { fn key() -> str }
assert FileStorage: Storage // static checkRelated diagnostics
schema-attr, no-entry-point, impl-foreign-type, unknown-method, explicit-interface, interface-not-satisfied, bad-init, missing-field, must-close, positional-literal, sealed-literal, ambiguous-embed, missing-override, override-without-open