OxL Справочник OxL
РусскийEnglish

kw fn

Зарезервированное слово

Список слов: §1.4

Синтаксис

ebnf
Fn          = [ "comptime" [ "literal" ] | "unsafe" ] "fn" Ident [ Generics ] "(" [ Params ] ")"
              [ "->" Type ] [ Effects ] [ Where ] { Contract } ( Block | "=>" Expr ) ;
ebnf
IMember     = "embed" Type | "type" Ident [ "=" Type ] | Receiver "fn" Sig [ "=>" Expr | Block ] ;
ebnf
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 ) ;
ebnf
AtomType    = Path [ "<" TypeArgs ">" ] | "(" [ Type { "," Type } ] ")" | "[" Type [ ";" Expr ] "]"
            | "&" [ "var" ] Type | "*" [ "var" ] Type | ( "frozen" | "sync" | "view" | "dyn" ) Type
            | "fn" "(" [ Type { "," Type } ] ")" [ "->" Type ] [ Effects ] [ "escaping" ] | "never" ;

Грамматика: Прил. A

Определяется в

Примеры

oxl
@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 Пользовательские сериализаторы

oxl
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     // метод по умолчанию
}

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                      // статическая проверка

— 4.6 Интерфейсы

Связанные диагностики

schema-attr, bad-main, 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

См. также