Module starlark::values::record

source ·
Expand description

A record type, comprising of a fixed set of fields.

Calling record() produces a RecordType. Calling RecordType produces a Record. The field names of the record are only stored once, potentially reducing memory usage. Created in Starlark using the record() function, which accepts keyword arguments. The keys become field names, and values are the types. Calling the resulting function produces an actual record.

IpAddress = record(host=str.type, port=int.type)
rec = IpAddress(host="localhost", port=80)
rec.port == 80

It is also possible to use field(type, default) type to give defaults:

IpAddress = record(host=str.type, port=field(int.type, 80))
rec = IpAddress(host="localhost")
rec.port == 80

Type Aliases§