Skip to content

Commit 769e9b6

Browse files
committed
Write briefly about syntax extension in the syntax section
The currently existing syntax extension facilities don't really merit their own section.
1 parent 5b0c103 commit 769e9b6

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

doc/tutorial/data.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ name as the field.
6161
{x, y} { /* Simply bind the fields */ }
6262
}
6363

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.
6768

6869
## Tags
6970

doc/tutorial/ext.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

doc/tutorial/order

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ args
88
generic
99
mod
1010
ffi
11-
ext
1211
task
1312
test

doc/tutorial/syntax.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Syntax Basics
22

3-
FIXME: briefly mention syntax extentions, #fmt
4-
53
## Braces
64

75
Assuming you've programmed in any C-family language (C++, Java,
@@ -307,3 +305,26 @@ written like this:
307305
#[cfg(target_os = "win32")];
308306
/* ... */
309307
}
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"));

0 commit comments

Comments
 (0)