File tree Expand file tree Collapse file tree 4 files changed +27
-9
lines changed Expand file tree Collapse file tree 4 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -61,9 +61,10 @@ name as the field.
61
61
{x, y} { /* Simply bind the fields */ }
62
62
}
63
63
64
- When you are not interested in all the fields of a record, a record
65
- pattern may end with ` , _ ` (as in ` {field1, _} ` ) to indicate that
66
- you're ignoring all other fields.
64
+ The field names of a record do not have to appear in a pattern in the
65
+ same order they appear in the type. When you are not interested in all
66
+ the fields of a record, a record pattern may end with ` , _ ` (as in
67
+ ` {field1, _} ` ) to indicate that you're ignoring all other fields.
67
68
68
69
## Tags
69
70
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 8
8
generic
9
9
mod
10
10
ffi
11
- ext
12
11
task
13
12
test
Original file line number Diff line number Diff line change 1
1
# Syntax Basics
2
2
3
- FIXME: briefly mention syntax extentions, #fmt
4
-
5
3
## Braces
6
4
7
5
Assuming you've programmed in any C-family language (C++, Java,
@@ -307,3 +305,26 @@ written like this:
307
305
#[cfg(target_os = "win32")];
308
306
/* ... */
309
307
}
308
+
309
+ ## Syntax extensions
310
+
311
+ There are plans to support user-defined syntax (macros) in Rust. This
312
+ currently only exists in very limited form.
313
+
314
+ The compiler defines a few built-in syntax extensions. The most useful
315
+ one is ` #fmt ` , a printf-style text formatting macro that is expanded
316
+ at compile time.
317
+
318
+ std::io::writeln(#fmt("%s is %d", "the answer", 42));
319
+
320
+ ` #fmt ` supports most of the directives that [ printf] [ pf ] supports, but
321
+ will give you a compile-time error when the types of the directives
322
+ don't match the types of the arguments.
323
+
324
+ [ pf ] : http://en.cppreference.com/w/cpp/io/c/fprintf
325
+
326
+ All syntax extensions look like ` #word ` . Another built-in one is
327
+ ` #env ` , which will look up its argument as an environment variable at
328
+ compile-time.
329
+
330
+ std::io::writeln(#env("PATH"));
You can’t perform that action at this time.
0 commit comments