10
10
11
11
Before a record can be used it must be declared using the `record` syntax:
12
12
13
- -- ft.code: declaring a record
13
+ -- ft.code: Declaring a Person record
14
14
lang: ftd
15
15
16
16
\-- record person:
17
- name: caption
18
- age: integer
19
- bio: optional body
17
+ caption name:
18
+ integer age:
19
+ optional body bio:
20
20
21
21
-- ft.markdown:
22
22
23
23
Here we are creating a record. The name of the record is `person`. It has three
24
24
fields: `name`, `age` and `bio`.
25
25
26
+ -- ft.code: Declaring a Company record
27
+ lang: ftd
28
+
29
+ \-- record company:
30
+ caption name:
31
+ person list employees:
32
+
33
+ -- ft.markdown:
34
+
35
+ In this case, the name of the record is `company`. It has two fields:
36
+ caption `name` and list of `employees` of `person` type.
37
+
38
+ -- ft.h1: Declaring a `record` with default values
39
+
40
+ Sometimes, the programmer might want to provide default values to the record
41
+ fields, in case if he/she doesn't specify those during initialization.
42
+
43
+ -- ft.code: Declaring a Person record with default field values
44
+ lang: ftd
45
+
46
+ \-- record person:
47
+ caption name: Undefined
48
+ integer age:
49
+ optional body bio: Not specified
50
+
51
+ \;; << Alternative way >>
52
+ \-- record person:
53
+ caption name: Undefined
54
+ integer age:
55
+
56
+ \-- optional body person.bio:
57
+
58
+ No bio is specified for this person.
59
+
60
+ -- ft.code: Declaring a Company record with default field values
61
+ lang: ftd
62
+
63
+ \-- record company:
64
+ string name: FifthTry
65
+
66
+ \-- person list company.employees:
67
+
68
+ \-- person:
69
+ name: Arpita
70
+ age: 22
71
+
72
+ \-- person:
73
+ name: Abrar
74
+ age: 24
75
+
76
+ \-- end: company.employees
77
+
78
+
26
79
-- ft.h1: Field Types
27
80
28
81
Fields can be either one of the [built-in types](built-in-types/),
@@ -49,19 +102,20 @@ so it's not a problem. Had it been `body` the above would not have been valid.
49
102
50
103
-- ft.h1: Record Field Update Syntax
51
104
105
+ The field which needs to be updated has to be mutable before updating its value.
52
106
An individual field of a record can be updated using a syntax like this:
53
107
54
108
-- ft.code:
55
109
lang: ftd
56
110
57
- \-- person john-snow: John Snow
58
- age: 14
111
+ \-- person $ john-snow: John Snow
112
+ $ age: 14
59
113
60
- \-- john-snow.age: 15
114
+ \-- $ john-snow.age: 15
61
115
62
116
-- ft.markdown:
63
117
64
- Here we have used `-- john-snow.age: 15` to update a single field of a record.
118
+ Here we have used `-- $ john-snow.age: 15` to update a single field of a record.
65
119
66
120
This also works if the field is a list:
67
121
@@ -72,12 +126,12 @@ lang: ftd
72
126
caption name:
73
127
string list alias:
74
128
75
- \-- person john-snow: John Snow
129
+ \-- person $ john-snow: John Snow
76
130
77
- \-- john-snow.alias: Aegon Targaryen
78
- \-- john-snow.alias: Lord Crow
79
- \-- john-snow.alias: The White Wolf
80
- \-- john-snow.alias: The Prince That Was Promised
131
+ \-- $ john-snow.alias: Aegon Targaryen
132
+ \-- $ john-snow.alias: Lord Crow
133
+ \-- $ john-snow.alias: The White Wolf
134
+ \-- $ john-snow.alias: The Prince That Was Promised
81
135
82
136
83
137
-- ft.h1: Reading A Record From Rust
0 commit comments