kw data
Reserved keyword
The list of words: §1.4
Syntax
Data = "data" Ident [ Generics ] [ Where ] "{" { Member } "}" ;Grammar: App. A
Defined in
- 4.2 data — A field: visibility?
- 4.8 Generics — Parameters: type parameters T, constant parameters const N
- 9.5 User-defined serialisers — Level 1 — representation through another type (Repr), acts in all formats and in schemas
- 4.3 Construction and constructors — Literal. T{ f1: e1, f2, ..base }
- 4.7 Embedding and overriding — There is no implementation inheritance.
- 6.5 Errors — There are no exceptions.
- 9.2 Field numbers and schema — Every field of a data and every variant of an enum has a stable tag (the number in the wire format).
- 9.3 The OxL wire format — The OxL binary format is protobuf 3 encoding with the following mappings
Examples
pub(api) data User {
pub(api) id: UserId
pub(api) name: Name
pub(api) email: Email? @since(2)
role: Role = Role.User
createdAt: Time = now()
invariant name != "admin" || role == Role.Admin
}— 4.2 data
fn max<T>(a: T, b: T) -> T where T: Ord => if a > b { a } else { b }
data Page<T> where T: Serializable { items: List<T>; next: Cursor? }
data Matrix<const R: usize, const C: usize> { cells: [f64; R * C] }
fn pack<T>(x: T) -> bytes where T: Serializable, size_of(T) <= 4KiB
data Cache<K: Hash + Eq, V = bytes> { … }Related diagnostics
unknown-field, bound-not-satisfied, generic-args, schema-attr, bad-init, missing-field, must-close, positional-literal, sealed-literal, ambiguous-embed, missing-override, override-without-open, fail-type, question-context