-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeTypeToConcept.json
More file actions
196 lines (196 loc) · 8.99 KB
/
nodeTypeToConcept.json
File metadata and controls
196 lines (196 loc) · 8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
[
{
"title": "`use` statement",
"example": "`use std::fmt;`",
"nodeType": "use_declaration",
"nodeQuery": "(use_declaration)",
"tokenSpan": [0, 3],
"level": 1,
"explanation": {
"text":
"By default, Rust brings only a few types into the scope of every program in the prelude. If a type you want to use isn’t in the prelude, you have to bring that type into scope explicitly with a use statement.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html#processing-a-guess"
]
}
},
{
"title": "nested `use` path list",
"example": "`use std::{ fmt, path };`",
"nodeType": "use_list",
"nodeQuery": "(use_list)",
"tokenSpan": [-2, 1],
"level": 1,
"explanation": {
"text":
"If we’re using multiple items defined in the same package or same module, listing each item on its own line can take up a lot of vertical space in our files. Instead, we can use nested paths to bring the same items into scope in one line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that differ.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#using-nested-paths-to-clean-up-large-use-lists"
]
}
},
{
"title": "Enumeration",
"example": "`enum LoadingState { Loading, Failure, Success }`",
"nodeType": "enum_item",
"nodeQuery": "(enum_item)",
"tokenSpan": [0, 4],
"level": 1,
"explanation": {
"text":
"Enums allow you to define a type by enumerating its possible values. An enum encodes meaning along with data, and pattern matching an enum in the `match` expression also makes it easy to run different code for different enum values.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch06-00-enums.html"
]
}
},
{
"title": "Trait implementation",
"example": "`impl fmt::Display for MyType { ... }`)",
"nodeType": "impl_item",
"nodeQuery": "(impl_item trait: (type_identifier))",
"tokenSpan": [0, 4],
"explanation": {
"text":
"A trait tells the Rust compiler about functionality a particular type has and can share with other types. Implementing a trait on a type is similar to implementing regular methods. The difference is that after `impl`, we put the trait name that we want to implement, then use the `for` keyword, and then specify the name of the type we want to implement the trait for. Within the `impl` block, we put the method signatures that the trait definition has defined.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch10-02-traits.html#implementing-a-trait-on-a-type"
]
}
},
{
"title": "Reference type",
"example": "`fn readOnly(data: &[u8]) { ... }`",
"nodeType": "reference_type",
"nodeQuery": "(reference_type)",
"tokenSpan": [0, 1],
"explanation": {
"text":
"A reference type indicates a parameter or other scoped identifier that is borrowed: you can't change the borrowed item (unless it is also declared mutable with `mut`). The function will also not deallocate the resource when it goes out of scope. This allows for safe data sharing between functions/scopes without copying.",
"sourceUrls": [
"https://doc.rust-lang.org/1.30.0/book/first-edition/references-and-borrowing.html#borrowing"
]
}
},
{
"title": "Mutable reference",
"example": "`fn canChange(data: &mut Vec<u8>) { ... }`",
"nodeType": "mutable_specifier",
"nodeQuery": "(mutable_specifier)",
"tokenSpan": [0, 3],
"explanation": {
"text":
"A mutable reference allows read/write access to the referred item. You'll often need to use asterisks to access the contents of a mutable reference, e.g. `let y = &mut x; *y += 1;`.",
"sourceUrls": [
"https://doc.rust-lang.org/1.30.0/book/first-edition/references-and-borrowing.html#borrowing"
]
}
},
{
"title": "`match` operator",
"nodeType": "match_expression",
"nodeQuery": "(match_expression)",
"tokenSpan": [0, 5],
"explanation": {
"text":
"Rust has an extremely powerful control flow operator called `match` that allows you to compare a value against a series of patterns and then execute code based on which pattern matches. The power of match comes from the expressiveness of the patterns and the fact that the compiler confirms that all possible cases are handled.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch06-02-match.html"
]
}
},
{
"title": "Macro parameters",
"example": "`println!(\"Hello, {}\", name);`",
"nodeType": "token_tree",
"nodeQuery": "(macro_invocation (token_tree))",
"tokenSpan": [-1, 1],
"explanation": {
"text":
"Macros are specially written code that expands to produce more code; the `!` here indicates a macro is being called. Macros can take parameters in parentheses in the same way functions do. `println!` and `vec!` are two common macros in Rust.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch19-06-macros.html#function-like-macros"
]
}
},
{
"title": "Macro invocation",
"example": "`println!(\"Hello, {}\", name);`",
"nodeType": "macro_invocation",
"nodeQuery": "(macro_invocation)",
"tokenSpan": [-1, 1],
"explanation": {
"text":
"Macros are specially written code that expands to produce more code; the `!` here indicates a macro is being called. `println!` and `vec!` are two common macros in Rust.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch19-06-macros.html#function-like-macros"
]
}
},
{
"title": "Scoped identifier",
"example": "`std::thread::LocalKey`",
"nodeType": "scoped_identifier",
"nodeQuery": "(scoped_identifier)",
"explanation": {
"text":
"To show Rust where to find an identifier, we use a path in the same way we use a path when navigating a filesystem. If we want to call a function or use a type, we need to know its path. Paths are composed of one or more nested modules and types separated by double colons (::), followed by an item's identifier.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#paths-for-referring-to-an-item-in-the-module-tree"
]
}
},
{
"title": "Generic type",
"example": "`fn largest<T>(list: &[T]) -> T { ... }`",
"nodeType": "generic_type",
"nodeQuery": "(generic_type)",
"explanation": {
"text":
"Generics are abstract stand-ins for concrete types or other properties. Some common examples are `Option<T>`, `Vec<T>`, and `struct Point<T> { x: T, y: T, }`. They allow you to write code that defines behavior and relationships that work for multiple concrete types, without repeating yourself.",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch10-01-syntax.html#generic-data-types"
]
}
},
{
"title": "Error propagation",
"example": "`let caller = get_first_argument()?;`",
"nodeType": "try_expression",
"nodeQuery": "(try_expression)",
"explanation": {
"text":
"The `?` placed after a `Result` makes a common error handling pattern more concise: if the value of the `Result` is an `Ok`, the value inside the `Ok` will get returned from this expression, and the program will continue. If the value is an `Err`, the `Err` will be returned from the whole function as if we had used the return keyword",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator"
]
}
},
{
"title": "Scoped imports",
"example": "`use some_module::some_enum::some_value;`",
"nodeType": "scoped_use_list",
"nodeQuery": "(scoped_use_list)",
"explanation": {
"text":
"The `::` in a `use` statement separates components of a path that describe how to import an identifier from other modules and types. They may be absolute or relative (see below).",
"sourceUrls": [
"https://doc.rust-lang.org/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#paths-for-referring-to-an-item-in-the-module-tree"
]
}
},
{
"title": "`self` as a parameter",
"example": "`fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { ... }`",
"nodeType": "self_parameter",
"nodeQuery": "(self_parameter)",
"level": 1,
"explanation": {
"text":
"In an implementation scope for a `struct` or `enum` (`impl`), the `self` parameter is used to access methods or condition on subtypes. This is commonly used to implement functionality that relies on other `struct` members, or (in combination with `match`) to do different things based on `enum` fields and values.",
"sourceUrls": [
"https://doc.rust-lang.org/1.18.0/book/second-edition/ch05-01-method-syntax.html#defining-methods"
]
}
}
]