kw type
Reserved keyword
The list of words: §1.4
Syntax
IMember = "embed" Type | "type" Ident [ "=" Type ] | Receiver "fn" Sig [ "=>" Expr | Block ] ;TypeAlias = "type" Ident [ Generics ] "=" ( [ "distinct" ] Type [ "where" Expr ] ) ;Grammar: App. A
Defined in
- 3.6 Aliases, new types and refined types — distinct T creates a new nominal type with the representation of T.
- 15.1 comptime — A comptime fn is executed only at compile time; comptime { …
- 6.5 Errors — There are no exceptions.
- 15.2 Reflection — reflect(T) -> TypeInfo (comptime only)
- 1.3 Identifiers — Identifier: XID_Start | "_", then XID_Continue* (Unicode UAX #31).
- 1.4 Keywords — Reserved (cannot be used as names)
- 1.5 Literals — Rules:
- 4.6 Interfaces — Interfaces are structural
Examples
type Bytes2 = [u8; 2] // alias, the same type
type UserId = distinct u64 // a new type, no implicit conversions
type Port = u16 where 1..=65535 // refined type
type Name = str where len(1..=64)
type Email = str where matches(re".+@.+\..+")— 3.6 Aliases, new types and refined types
type NetError = Timeout | Unavailable | Cancelled | AccessDenied | ProtocolErrorRelated diagnostics
refinement-violated, comptime-error, not-comptime, fail-type, question-context, unhandled-error, bad-label, bad-format-spec, invalid-char-literal, invalid-date, invalid-duration, invalid-escape, invalid-number, literal-overflow