]> git.lizzy.rs Git - rust.git/blob - doc/po/rust.md.pot
9bc3fb1d16e2abd04888315bb56e21a2daa85f5f
[rust.git] / doc / po / rust.md.pot
1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR The Rust Project Developers
3 # This file is distributed under the same license as the Rust package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 #
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: Rust 0.8-pre\n"
10 "POT-Creation-Date: 2013-08-12 02:06+0900\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
14 "Language: \n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
18
19 #. type: Plain text
20 #: doc/rust.md:2
21 msgid "% Rust Reference Manual"
22 msgstr ""
23
24 #. type: Plain text
25 #: doc/rust.md:4 doc/rustpkg.md:4 doc/tutorial.md:4
26 #: doc/tutorial-borrowed-ptr.md:4 doc/tutorial-ffi.md:4
27 #: doc/tutorial-macros.md:4 doc/tutorial-tasks.md:4
28 msgid "# Introduction"
29 msgstr ""
30
31 #. type: Plain text
32 #: doc/rust.md:7
33 msgid ""
34 "This document is the reference manual for the Rust programming language. It "
35 "provides three kinds of material:"
36 msgstr ""
37
38 #. type: Bullet: '  - '
39 #: doc/rust.md:15
40 msgid ""
41 "Chapters that formally define the language grammar and, for each construct, "
42 "informally describe its semantics and give examples of its use."
43 msgstr ""
44
45 #. type: Bullet: '  - '
46 #: doc/rust.md:15
47 msgid ""
48 "Chapters that informally describe the memory model, concurrency model, "
49 "runtime services, linkage model and debugging facilities."
50 msgstr ""
51
52 #. type: Bullet: '  - '
53 #: doc/rust.md:15
54 msgid ""
55 "Appendix chapters providing rationale and references to languages that "
56 "influenced the design."
57 msgstr ""
58
59 #. type: Plain text
60 #: doc/rust.md:19
61 msgid ""
62 "This document does not serve as a tutorial introduction to the language. "
63 "Background familiarity with the language is assumed. A separate [tutorial] "
64 "document is available to help acquire such background familiarity."
65 msgstr ""
66
67 #. type: Plain text
68 #: doc/rust.md:24
69 msgid ""
70 "This document also does not serve as a reference to the [standard] or "
71 "[extra] libraries included in the language distribution. Those libraries are "
72 "documented separately by extracting documentation attributes from their "
73 "source code."
74 msgstr ""
75
76 #. type: Plain text
77 #: doc/rust.md:28
78 msgid ""
79 "[tutorial]: tutorial.html [standard]: std/index.html [extra]: extra/index."
80 "html"
81 msgstr ""
82
83 #. type: Plain text
84 #: doc/rust.md:30 doc/rustpkg.md:8
85 msgid "## Disclaimer"
86 msgstr ""
87
88 #. type: Plain text
89 #: doc/rust.md:34
90 msgid ""
91 "Rust is a work in progress. The language continues to evolve as the design "
92 "shifts and is fleshed out in working code. Certain parts work, certain parts "
93 "do not, certain parts will be removed or changed."
94 msgstr ""
95
96 #. type: Plain text
97 #: doc/rust.md:39
98 msgid ""
99 "This manual is a snapshot written in the present tense. All features "
100 "described exist in working code unless otherwise noted, but some are quite "
101 "primitive or remain to be further modified by planned work. Some may be "
102 "temporary. It is a *draft*, and we ask that you not take anything you read "
103 "here as final."
104 msgstr ""
105
106 #. type: Plain text
107 #: doc/rust.md:43
108 msgid ""
109 "If you have suggestions to make, please try to focus them on *reductions* to "
110 "the language: possible features that can be combined or omitted. We aim to "
111 "keep the size and complexity of the language under control."
112 msgstr ""
113
114 #. type: Plain text
115 #: doc/rust.md:52
116 msgid ""
117 "> **Note:** The grammar for Rust given in this document is rough and > very "
118 "incomplete; only a modest number of sections have accompanying grammar > "
119 "rules. Formalizing the grammar accepted by the Rust parser is ongoing work, "
120 "> but future versions of this document will contain a complete > grammar. "
121 "Moreover, we hope that this grammar will be extracted and verified > as "
122 "LL(1) by an automated grammar-analysis tool, and further tested against the "
123 "> Rust sources. Preliminary versions of this automation exist, but are not "
124 "yet > complete."
125 msgstr ""
126
127 #. type: Plain text
128 #: doc/rust.md:54
129 msgid "# Notation"
130 msgstr ""
131
132 #. type: Plain text
133 #: doc/rust.md:62
134 msgid ""
135 "Rust's grammar is defined over Unicode codepoints, each conventionally "
136 "denoted `U+XXXX`, for 4 or more hexadecimal digits `X`. _Most_ of Rust's "
137 "grammar is confined to the ASCII range of Unicode, and is described in this "
138 "document by a dialect of Extended Backus-Naur Form (EBNF), specifically a "
139 "dialect of EBNF supported by common automated LL(k) parsing tools such as "
140 "`llgen`, rather than the dialect given in ISO 14977. The dialect can be "
141 "defined self-referentially as follows:"
142 msgstr ""
143
144 #. type: Plain text
145 #: doc/rust.md:64
146 msgid "~~~~~~~~ {.ebnf .notation}"
147 msgstr ""
148
149 #. type: Plain text
150 #: doc/rust.md:72
151 #, no-wrap
152 msgid ""
153 "grammar : rule + ;\n"
154 "rule    : nonterminal ':' productionrule ';' ;\n"
155 "productionrule : production [ '|' production ] * ;\n"
156 "production : term * ;\n"
157 "term : element repeats ;\n"
158 "element : LITERAL | IDENTIFIER | '[' productionrule ']' ;\n"
159 "repeats : [ '*' | '+' ] NUMBER ? | NUMBER ? | '?' ;\n"
160 msgstr ""
161
162 #. type: Plain text
163 #: doc/rust.md:74 doc/rust.md:416 doc/rust.md:486
164 msgid "~~~~~~~~"
165 msgstr ""
166
167 #. type: Plain text
168 #: doc/rust.md:76
169 msgid "Where:"
170 msgstr ""
171
172 #. type: Bullet: '  - '
173 #: doc/rust.md:89
174 msgid "Whitespace in the grammar is ignored."
175 msgstr ""
176
177 #. type: Bullet: '  - '
178 #: doc/rust.md:89
179 msgid "Square brackets are used to group rules."
180 msgstr ""
181
182 #. type: Plain text
183 #: doc/rust.md:89
184 #, no-wrap
185 msgid ""
186 "  - `LITERAL` is a single printable ASCII character, or an escaped hexadecimal\n"
187 "     ASCII code of the form `\\xQQ`, in single quotes, denoting the corresponding\n"
188 "     Unicode codepoint `U+00QQ`.\n"
189 "  - `IDENTIFIER` is a nonempty string of ASCII letters and underscores.\n"
190 "  - The `repeat` forms apply to the adjacent `element`, and are as follows:\n"
191 "    - `?` means zero or one repetition\n"
192 "    - `*` means zero or more repetitions\n"
193 "    - `+` means one or more repetitions\n"
194 "    - NUMBER trailing a repeat symbol gives a maximum repetition count\n"
195 "    - NUMBER on its own gives an exact repetition count\n"
196 msgstr ""
197
198 #. type: Plain text
199 #: doc/rust.md:91
200 msgid "This EBNF dialect should hopefully be familiar to many readers."
201 msgstr ""
202
203 #. type: Plain text
204 #: doc/rust.md:93
205 msgid "## Unicode productions"
206 msgstr ""
207
208 #. type: Plain text
209 #: doc/rust.md:98
210 msgid ""
211 "A few productions in Rust's grammar permit Unicode codepoints outside the "
212 "ASCII range.  We define these productions in terms of character properties "
213 "specified in the Unicode standard, rather than in terms of ASCII-range "
214 "codepoints.  The section [Special Unicode Productions](#special-unicode-"
215 "productions) lists these productions."
216 msgstr ""
217
218 #. type: Plain text
219 #: doc/rust.md:100
220 msgid "## String table productions"
221 msgstr ""
222
223 #. type: Plain text
224 #: doc/rust.md:109
225 msgid ""
226 "Some rules in the grammar -- notably [unary operators](#unary-operator-"
227 "expressions), [binary operators](#binary-operator-expressions), and "
228 "[keywords](#keywords) -- are given in a simplified form: as a listing of a "
229 "table of unquoted, printable whitespace-separated strings. These cases form "
230 "a subset of the rules regarding the [token](#tokens) rule, and are assumed "
231 "to be the result of a lexical-analysis phase feeding the parser, driven by a "
232 "DFA, operating over the disjunction of all such string table entries."
233 msgstr ""
234
235 #. type: Plain text
236 #: doc/rust.md:113
237 msgid ""
238 "When such a string enclosed in double-quotes (`\"`) occurs inside the "
239 "grammar, it is an implicit reference to a single member of such a string "
240 "table production. See [tokens](#tokens) for more information."
241 msgstr ""
242
243 #. type: Plain text
244 #: doc/rust.md:116
245 msgid "# Lexical structure"
246 msgstr ""
247
248 #. type: Plain text
249 #: doc/rust.md:118
250 msgid "## Input format"
251 msgstr ""
252
253 #. type: Plain text
254 #: doc/rust.md:124
255 msgid ""
256 "Rust input is interpreted as a sequence of Unicode codepoints encoded in "
257 "UTF-8, normalized to Unicode normalization form NFKC.  Most Rust grammar "
258 "rules are defined in terms of printable ASCII-range codepoints, but a small "
259 "number are defined in terms of Unicode properties or explicit codepoint "
260 "lists.  ^[Substitute definitions for the special Unicode productions are "
261 "provided to the grammar verifier, restricted to ASCII range, when verifying "
262 "the grammar in this document.]"
263 msgstr ""
264
265 #. type: Plain text
266 #: doc/rust.md:126
267 msgid "## Special Unicode Productions"
268 msgstr ""
269
270 #. type: Plain text
271 #: doc/rust.md:129
272 msgid ""
273 "The following productions in the Rust grammar are defined in terms of "
274 "Unicode properties: `ident`, `non_null`, `non_star`, `non_eol`, "
275 "`non_slash_or_star`, `non_single_quote` and `non_double_quote`."
276 msgstr ""
277
278 #. type: Plain text
279 #: doc/rust.md:131
280 msgid "### Identifiers"
281 msgstr ""
282
283 #. type: Plain text
284 #: doc/rust.md:133
285 msgid ""
286 "The `ident` production is any nonempty Unicode string of the following form:"
287 msgstr ""
288
289 #. type: Bullet: '   - '
290 #: doc/rust.md:136
291 msgid "The first character has property `XID_start`"
292 msgstr ""
293
294 #. type: Bullet: '   - '
295 #: doc/rust.md:136
296 msgid "The remaining characters have property `XID_continue`"
297 msgstr ""
298
299 #. type: Plain text
300 #: doc/rust.md:138
301 msgid "that does _not_ occur in the set of [keywords](#keywords)."
302 msgstr ""
303
304 #. type: Plain text
305 #: doc/rust.md:142
306 msgid ""
307 "Note: `XID_start` and `XID_continue` as character properties cover the "
308 "character ranges used to form the more familiar C and Java language-family "
309 "identifiers."
310 msgstr ""
311
312 #. type: Plain text
313 #: doc/rust.md:144
314 msgid "### Delimiter-restricted productions"
315 msgstr ""
316
317 #. type: Plain text
318 #: doc/rust.md:146
319 msgid ""
320 "Some productions are defined by exclusion of particular Unicode characters:"
321 msgstr ""
322
323 #. type: Bullet: '  - '
324 #: doc/rust.md:153
325 msgid "`non_null` is any single Unicode character aside from `U+0000` (null)"
326 msgstr ""
327
328 #. type: Bullet: '  - '
329 #: doc/rust.md:153
330 msgid "`non_eol` is `non_null` restricted to exclude `U+000A` (`'\\n'`)"
331 msgstr ""
332
333 #. type: Bullet: '  - '
334 #: doc/rust.md:153
335 msgid "`non_star` is `non_null` restricted to exclude `U+002A` (`*`)"
336 msgstr ""
337
338 #. type: Bullet: '  - '
339 #: doc/rust.md:153
340 msgid ""
341 "`non_slash_or_star` is `non_null` restricted to exclude `U+002F` (`/`) and `U"
342 "+002A` (`*`)"
343 msgstr ""
344
345 #. type: Bullet: '  - '
346 #: doc/rust.md:153
347 msgid "`non_single_quote` is `non_null` restricted to exclude `U+0027` (`'`)"
348 msgstr ""
349
350 #. type: Bullet: '  - '
351 #: doc/rust.md:153
352 msgid "`non_double_quote` is `non_null` restricted to exclude `U+0022` (`\"`)"
353 msgstr ""
354
355 #. type: Plain text
356 #: doc/rust.md:155
357 msgid "## Comments"
358 msgstr ""
359
360 #. type: Plain text
361 #: doc/rust.md:162
362 msgid ""
363 "~~~~~~~~ {.ebnf .gram} comment : block_comment | line_comment ; "
364 "block_comment : \"/*\" block_comment_body * '*' + '/' ; block_comment_body : "
365 "non_star * | '*' + non_slash_or_star ; line_comment : \"//\" non_eol * ; "
366 "~~~~~~~~"
367 msgstr ""
368
369 #. type: Plain text
370 #: doc/rust.md:165
371 msgid ""
372 "Comments in Rust code follow the general C++ style of line and block-comment "
373 "forms, with no nesting of block-comment delimiters."
374 msgstr ""
375
376 #. type: Plain text
377 #: doc/rust.md:170
378 msgid ""
379 "Line comments beginning with _three_ slashes (`///`), and block comments "
380 "beginning with a repeated asterisk in the block-open sequence (`/**`), are "
381 "interpreted as a special syntax for `doc` [attributes](#attributes).  That "
382 "is, they are equivalent to writing `#[doc \"...\"]` around the comment's "
383 "text."
384 msgstr ""
385
386 #. type: Plain text
387 #: doc/rust.md:172
388 msgid "Non-doc comments are interpreted as a form of whitespace."
389 msgstr ""
390
391 #. type: Plain text
392 #: doc/rust.md:174
393 msgid "## Whitespace"
394 msgstr ""
395
396 #. type: Plain text
397 #: doc/rust.md:179
398 msgid ""
399 "~~~~~~~~ {.ebnf .gram} whitespace_char : '\\x20' | '\\x09' | '\\x0a' | "
400 "'\\x0d' ; whitespace : [ whitespace_char | comment ] + ; ~~~~~~~~"
401 msgstr ""
402
403 #. type: Plain text
404 #: doc/rust.md:183
405 msgid ""
406 "The `whitespace_char` production is any nonempty Unicode string consisting "
407 "of any of the following Unicode characters: `U+0020` (space, `' '`), `U"
408 "+0009` (tab, `'\\t'`), `U+000A` (LF, `'\\n'`), `U+000D` (CR, `'\\r'`)."
409 msgstr ""
410
411 #. type: Plain text
412 #: doc/rust.md:186
413 msgid ""
414 "Rust is a \"free-form\" language, meaning that all forms of whitespace serve "
415 "only to separate _tokens_ in the grammar, and have no semantic significance."
416 msgstr ""
417
418 #. type: Plain text
419 #: doc/rust.md:189
420 msgid ""
421 "A Rust program has identical meaning if each whitespace element is replaced "
422 "with any other legal whitespace element, such as a single space character."
423 msgstr ""
424
425 #. type: Plain text
426 #: doc/rust.md:191
427 msgid "## Tokens"
428 msgstr ""
429
430 #. type: Plain text
431 #: doc/rust.md:196
432 msgid ""
433 "~~~~~~~~ {.ebnf .gram} simple_token : keyword | unop | binop ; token : "
434 "simple_token | ident | literal | symbol | whitespace token ; ~~~~~~~~"
435 msgstr ""
436
437 #. type: Plain text
438 #: doc/rust.md:201
439 msgid ""
440 "Tokens are primitive productions in the grammar defined by regular (non-"
441 "recursive) languages. \"Simple\" tokens are given in [string table "
442 "production](#string-table-productions) form, and occur in the rest of the "
443 "grammar as double-quoted strings. Other tokens have exact rules given."
444 msgstr ""
445
446 #. type: Plain text
447 #: doc/rust.md:203
448 msgid "### Keywords"
449 msgstr ""
450
451 #. type: Plain text
452 #: doc/rust.md:205
453 msgid "The keywords are the following strings:"
454 msgstr ""
455
456 #. type: Plain text
457 #: doc/rust.md:222
458 msgid ""
459 "~~~~~~~~ {.keyword} as break do else enum extern false fn for if impl let "
460 "loop match mod mut priv pub ref return self static struct super true trait "
461 "type unsafe use while ~~~~~~~~"
462 msgstr ""
463
464 #. type: Plain text
465 #: doc/rust.md:225
466 msgid ""
467 "Each of these keywords has special meaning in its grammar, and all of them "
468 "are excluded from the `ident` rule."
469 msgstr ""
470
471 #. type: Plain text
472 #: doc/rust.md:227
473 msgid "### Literals"
474 msgstr ""
475
476 #. type: Plain text
477 #: doc/rust.md:233
478 msgid ""
479 "A literal is an expression consisting of a single token, rather than a "
480 "sequence of tokens, that immediately and directly denotes the value it "
481 "evaluates to, rather than referring to it by name or some other evaluation "
482 "rule. A literal is a form of constant expression, so is evaluated "
483 "(primarily)  at compile time."
484 msgstr ""
485
486 #. type: Plain text
487 #: doc/rust.md:237
488 msgid ""
489 "~~~~~~~~ {.ebnf .gram} literal : string_lit | char_lit | num_lit ; ~~~~~~~~"
490 msgstr ""
491
492 #. type: Plain text
493 #: doc/rust.md:239
494 msgid "#### Character and string literals"
495 msgstr ""
496
497 #. type: Plain text
498 #: doc/rust.md:243
499 msgid ""
500 "~~~~~~~~ {.ebnf .gram} char_lit : '\\x27' char_body '\\x27' ; string_lit : "
501 "'\"' string_body * '\"' ;"
502 msgstr ""
503
504 #. type: Plain text
505 #: doc/rust.md:246
506 #, no-wrap
507 msgid ""
508 "char_body : non_single_quote\n"
509 "          | '\\x5c' [ '\\x27' | common_escape ] ;\n"
510 msgstr ""
511
512 #. type: Plain text
513 #: doc/rust.md:249
514 #, no-wrap
515 msgid ""
516 "string_body : non_double_quote\n"
517 "            | '\\x5c' [ '\\x22' | common_escape ] ;\n"
518 msgstr ""
519
520 #. type: Plain text
521 #: doc/rust.md:255
522 #, no-wrap
523 msgid ""
524 "common_escape : '\\x5c'\n"
525 "              | 'n' | 'r' | 't'\n"
526 "              | 'x' hex_digit 2\n"
527 "              | 'u' hex_digit 4\n"
528 "              | 'U' hex_digit 8 ;\n"
529 msgstr ""
530
531 #. type: Plain text
532 #: doc/rust.md:263
533 #, no-wrap
534 msgid ""
535 "hex_digit : 'a' | 'b' | 'c' | 'd' | 'e' | 'f'\n"
536 "          | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'\n"
537 "          | dec_digit ;\n"
538 "dec_digit : '0' | nonzero_dec ;\n"
539 "nonzero_dec: '1' | '2' | '3' | '4'\n"
540 "           | '5' | '6' | '7' | '8' | '9' ;\n"
541 "~~~~~~~~\n"
542 msgstr ""
543
544 #. type: Plain text
545 #: doc/rust.md:267
546 msgid ""
547 "A _character literal_ is a single Unicode character enclosed within two `U"
548 "+0027` (single-quote) characters, with the exception of `U+0027` itself, "
549 "which must be _escaped_ by a preceding U+005C character (`\\`)."
550 msgstr ""
551
552 #. type: Plain text
553 #: doc/rust.md:271
554 msgid ""
555 "A _string literal_ is a sequence of any Unicode characters enclosed within "
556 "two `U+0022` (double-quote) characters, with the exception of `U+0022` "
557 "itself, which must be _escaped_ by a preceding `U+005C` character (`\\`)."
558 msgstr ""
559
560 #. type: Plain text
561 #: doc/rust.md:275
562 msgid ""
563 "Some additional _escapes_ are available in either character or string "
564 "literals. An escape starts with a `U+005C` (`\\`) and continues with one of "
565 "the following forms:"
566 msgstr ""
567
568 #. type: Bullet: '  * '
569 #: doc/rust.md:290
570 msgid ""
571 "An _8-bit codepoint escape_ escape starts with `U+0078` (`x`) and is "
572 "followed by exactly two _hex digits_. It denotes the Unicode codepoint equal "
573 "to the provided hex value."
574 msgstr ""
575
576 #. type: Bullet: '  * '
577 #: doc/rust.md:290
578 msgid ""
579 "A _16-bit codepoint escape_ starts with `U+0075` (`u`) and is followed by "
580 "exactly four _hex digits_. It denotes the Unicode codepoint equal to the "
581 "provided hex value."
582 msgstr ""
583
584 #. type: Bullet: '  * '
585 #: doc/rust.md:290
586 msgid ""
587 "A _32-bit codepoint escape_ starts with `U+0055` (`U`) and is followed by "
588 "exactly eight _hex digits_. It denotes the Unicode codepoint equal to the "
589 "provided hex value."
590 msgstr ""
591
592 #. type: Bullet: '  * '
593 #: doc/rust.md:290
594 msgid ""
595 "A _whitespace escape_ is one of the characters `U+006E` (`n`), `U+0072` "
596 "(`r`), or `U+0074` (`t`), denoting the unicode values `U+000A` (LF), `U"
597 "+000D` (CR) or `U+0009` (HT) respectively."
598 msgstr ""
599
600 #. type: Bullet: '  * '
601 #: doc/rust.md:290
602 msgid ""
603 "The _backslash escape_ is the character U+005C (`\\`) which must be escaped "
604 "in order to denote *itself*."
605 msgstr ""
606
607 #. type: Plain text
608 #: doc/rust.md:292
609 msgid "#### Number literals"
610 msgstr ""
611
612 #. type: Plain text
613 #: doc/rust.md:294 doc/rust.md:406 doc/rust.md:473
614 msgid "~~~~~~~~ {.ebnf .gram}"
615 msgstr ""
616
617 #. type: Plain text
618 #: doc/rust.md:299
619 #, no-wrap
620 msgid ""
621 "num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?\n"
622 "        | '0' [       [ dec_digit | '_' ] + num_suffix ?\n"
623 "              | 'b'   [ '1' | '0' | '_' ] + int_suffix ?\n"
624 "              | 'x'   [ hex_digit | '_' ] + int_suffix ? ] ;\n"
625 msgstr ""
626
627 #. type: Plain text
628 #: doc/rust.md:301
629 msgid "num_suffix : int_suffix | float_suffix ;"
630 msgstr ""
631
632 #. type: Plain text
633 #: doc/rust.md:305
634 #, no-wrap
635 msgid ""
636 "int_suffix : 'u' int_suffix_size ?\n"
637 "           | 'i' int_suffix_size ? ;\n"
638 "int_suffix_size : [ '8' | '1' '6' | '3' '2' | '6' '4' ] ;\n"
639 msgstr ""
640
641 #. type: Plain text
642 #: doc/rust.md:311
643 msgid ""
644 "float_suffix : [ exponent | '.' dec_lit exponent ? ] ? float_suffix_ty ? ; "
645 "float_suffix_ty : 'f' [ '3' '2' | '6' '4' ] ; exponent : ['E' | 'e'] ['-' | "
646 "'+' ] ? dec_lit ; dec_lit : [ dec_digit | '_' ] + ; ~~~~~~~~"
647 msgstr ""
648
649 #. type: Plain text
650 #: doc/rust.md:315
651 msgid ""
652 "A _number literal_ is either an _integer literal_ or a _floating-point "
653 "literal_. The grammar for recognizing the two kinds of literals is mixed, as "
654 "they are differentiated by suffixes."
655 msgstr ""
656
657 #. type: Plain text
658 #: doc/rust.md:317
659 msgid "##### Integer literals"
660 msgstr ""
661
662 #. type: Plain text
663 #: doc/rust.md:319
664 msgid "An _integer literal_ has one of three forms:"
665 msgstr ""
666
667 #. type: Bullet: '  * '
668 #: doc/rust.md:326
669 msgid ""
670 "A _decimal literal_ starts with a *decimal digit* and continues with any "
671 "mixture of *decimal digits* and _underscores_."
672 msgstr ""
673
674 #. type: Bullet: '  * '
675 #: doc/rust.md:326
676 msgid ""
677 "A _hex literal_ starts with the character sequence `U+0030` `U+0078` (`0x`) "
678 "and continues as any mixture hex digits and underscores."
679 msgstr ""
680
681 #. type: Bullet: '  * '
682 #: doc/rust.md:326
683 msgid ""
684 "A _binary literal_ starts with the character sequence `U+0030` `U+0062` "
685 "(`0b`) and continues as any mixture binary digits and underscores."
686 msgstr ""
687
688 #. type: Plain text
689 #: doc/rust.md:330
690 msgid ""
691 "An integer literal may be followed (immediately, without any spaces) by an "
692 "_integer suffix_, which changes the type of the literal. There are two kinds "
693 "of integer literal suffix:"
694 msgstr ""
695
696 #. type: Bullet: '  * '
697 #: doc/rust.md:336
698 msgid ""
699 "The `i` and `u` suffixes give the literal type `int` or `uint`, respectively."
700 msgstr ""
701
702 #. type: Bullet: '  * '
703 #: doc/rust.md:336
704 msgid ""
705 "Each of the signed and unsigned machine types `u8`, `i8`, `u16`, `i16`, "
706 "`u32`, `i32`, `u64` and `i64` give the literal the corresponding machine "
707 "type."
708 msgstr ""
709
710 #. type: Plain text
711 #: doc/rust.md:343
712 msgid ""
713 "The type of an _unsuffixed_ integer literal is determined by type "
714 "inference.  If a integer type can be _uniquely_ determined from the "
715 "surrounding program context, the unsuffixed integer literal has that type.  "
716 "If the program context underconstrains the type, the unsuffixed integer "
717 "literal's type is `int`; if the program context overconstrains the type, it "
718 "is considered a static type error."
719 msgstr ""
720
721 #. type: Plain text
722 #: doc/rust.md:345
723 msgid "Examples of integer literals of various forms:"
724 msgstr ""
725
726 #. type: Plain text
727 #: doc/rust.md:350
728 #, no-wrap
729 msgid ""
730 "~~~~\n"
731 "123; 0xff00;                       // type determined by program context\n"
732 "                                   // defaults to int in absence of type\n"
733 "                                   // information\n"
734 msgstr ""
735
736 #. type: Plain text
737 #: doc/rust.md:356
738 #, no-wrap
739 msgid ""
740 "123u;                              // type uint\n"
741 "123_u;                             // type uint\n"
742 "0xff_u8;                           // type u8\n"
743 "0b1111_1111_1001_0000_i32;         // type i32\n"
744 "~~~~\n"
745 msgstr ""
746
747 #. type: Plain text
748 #: doc/rust.md:358
749 msgid "##### Floating-point literals"
750 msgstr ""
751
752 #. type: Plain text
753 #: doc/rust.md:360
754 msgid "A _floating-point literal_ has one of two forms:"
755 msgstr ""
756
757 #. type: Bullet: '* '
758 #: doc/rust.md:365
759 msgid ""
760 "Two _decimal literals_ separated by a period character `U+002E` (`.`), with "
761 "an optional _exponent_ trailing after the second decimal literal."
762 msgstr ""
763
764 #. type: Bullet: '* '
765 #: doc/rust.md:365
766 msgid "A single _decimal literal_ followed by an _exponent_."
767 msgstr ""
768
769 #. type: Plain text
770 #: doc/rust.md:372
771 msgid ""
772 "By default, a floating-point literal is of type `float`. A floating-point "
773 "literal may be followed (immediately, without any spaces) by a _floating-"
774 "point suffix_, which changes the type of the literal. There are three "
775 "floating-point suffixes: `f` (for the base `float` type), `f32`, and `f64` "
776 "(the 32-bit and 64-bit floating point types)."
777 msgstr ""
778
779 #. type: Plain text
780 #: doc/rust.md:374
781 msgid "Examples of floating-point literals of various forms:"
782 msgstr ""
783
784 #. type: Plain text
785 #: doc/rust.md:382
786 #, no-wrap
787 msgid ""
788 "~~~~\n"
789 "123.0;                             // type float\n"
790 "0.1;                               // type float\n"
791 "3f;                                // type float\n"
792 "0.1f32;                            // type f32\n"
793 "12E+99_f64;                        // type f64\n"
794 "~~~~\n"
795 msgstr ""
796
797 #. type: Plain text
798 #: doc/rust.md:384
799 msgid "##### Unit and boolean literals"
800 msgstr ""
801
802 #. type: Plain text
803 #: doc/rust.md:387
804 msgid ""
805 "The _unit value_, the only value of the type that has the same name, is "
806 "written as `()`.  The two values of the boolean type are written `true` and "
807 "`false`."
808 msgstr ""
809
810 #. type: Plain text
811 #: doc/rust.md:389
812 msgid "### Symbols"
813 msgstr ""
814
815 #. type: Plain text
816 #: doc/rust.md:395
817 #, no-wrap
818 msgid ""
819 "~~~~~~~~ {.ebnf .gram}\n"
820 "symbol : \"::\" \"->\"\n"
821 "       | '#' | '[' | ']' | '(' | ')' | '{' | '}'\n"
822 "       | ',' | ';' ;\n"
823 "~~~~~~~~\n"
824 msgstr ""
825
826 #. type: Plain text
827 #: doc/rust.md:401
828 msgid ""
829 "Symbols are a general class of printable [token](#tokens) that play "
830 "structural roles in a variety of grammar productions. They are catalogued "
831 "here for completeness as the set of remaining miscellaneous printable tokens "
832 "that do not otherwise appear as [unary operators](#unary-operator-"
833 "expressions), [binary operators](#binary-operator-expressions), or [keywords]"
834 "(#keywords)."
835 msgstr ""
836
837 #. type: Plain text
838 #: doc/rust.md:404
839 msgid "## Paths"
840 msgstr ""
841
842 #. type: Plain text
843 #: doc/rust.md:410
844 #, no-wrap
845 msgid ""
846 "expr_path : ident [ \"::\" expr_path_tail ] + ;\n"
847 "expr_path_tail : '<' type_expr [ ',' type_expr ] + '>'\n"
848 "               | expr_path ;\n"
849 msgstr ""
850
851 #. type: Plain text
852 #: doc/rust.md:414
853 #, no-wrap
854 msgid ""
855 "type_path : ident [ type_path_tail ] + ;\n"
856 "type_path_tail : '<' type_expr [ ',' type_expr ] + '>'\n"
857 "               | \"::\" type_path ;\n"
858 msgstr ""
859
860 #. type: Plain text
861 #: doc/rust.md:421
862 msgid ""
863 "A _path_ is a sequence of one or more path components _logically_ separated "
864 "by a namespace qualifier (`::`). If a path consists of only one component, "
865 "it may refer to either an [item](#items) or a [slot](#memory-slots) in a "
866 "local control scope. If a path has multiple components, it refers to an item."
867 msgstr ""
868
869 #. type: Plain text
870 #: doc/rust.md:425
871 msgid ""
872 "Every item has a _canonical path_ within its crate, but the path naming an "
873 "item is only meaningful within a given crate. There is no global namespace "
874 "across crates; an item's canonical path merely identifies it within the "
875 "crate."
876 msgstr ""
877
878 #. type: Plain text
879 #: doc/rust.md:427
880 msgid "Two examples of simple paths consisting of only identifier components:"
881 msgstr ""
882
883 #. type: Plain text
884 #: doc/rust.md:432
885 msgid "~~~~{.ignore} x; x::y::z; ~~~~"
886 msgstr ""
887
888 #. type: Plain text
889 #: doc/rust.md:439
890 msgid ""
891 "Path components are usually [identifiers](#identifiers), but the trailing "
892 "component of a path may be an angle-bracket-enclosed list of type arguments. "
893 "In [expression](#expressions) context, the type argument list is given after "
894 "a final (`::`) namespace qualifier in order to disambiguate it from a "
895 "relational expression involving the less-than symbol (`<`). In type "
896 "expression context, the final namespace qualifier is omitted."
897 msgstr ""
898
899 #. type: Plain text
900 #: doc/rust.md:441
901 msgid "Two examples of paths with type arguments:"
902 msgstr ""
903
904 #. type: Plain text
905 #: doc/rust.md:450
906 #, no-wrap
907 msgid ""
908 "~~~~\n"
909 "# use std::hashmap::HashMap;\n"
910 "# fn f() {\n"
911 "# fn id<T>(t: T) -> T { t }\n"
912 "type t = HashMap<int,~str>;  // Type arguments used in a type expression\n"
913 "let x = id::<int>(10);         // Type arguments used in a call expression\n"
914 "# }\n"
915 "~~~~\n"
916 msgstr ""
917
918 #. type: Plain text
919 #: doc/rust.md:452
920 msgid "# Syntax extensions"
921 msgstr ""
922
923 #. type: Plain text
924 #: doc/rust.md:457
925 msgid ""
926 "A number of minor features of Rust are not central enough to have their own "
927 "syntax, and yet are not implementable as functions. Instead, they are given "
928 "names, and invoked through a consistent syntax: `name!(...)`. Examples "
929 "include:"
930 msgstr ""
931
932 #. type: Bullet: '* '
933 #: doc/rust.md:466
934 msgid "`fmt!` : format data into a string"
935 msgstr ""
936
937 #. type: Bullet: '* '
938 #: doc/rust.md:466
939 msgid "`env!` : look up an environment variable's value at compile time"
940 msgstr ""
941
942 #. type: Bullet: '* '
943 #: doc/rust.md:466
944 msgid "`stringify!` : pretty-print the Rust expression given as an argument"
945 msgstr ""
946
947 #. type: Bullet: '* '
948 #: doc/rust.md:466
949 msgid "`proto!` : define a protocol for inter-task communication"
950 msgstr ""
951
952 #. type: Bullet: '* '
953 #: doc/rust.md:466
954 msgid "`include!` : include the Rust expression in the given file"
955 msgstr ""
956
957 #. type: Bullet: '* '
958 #: doc/rust.md:466
959 msgid "`include_str!` : include the contents of the given file as a string"
960 msgstr ""
961
962 #. type: Bullet: '* '
963 #: doc/rust.md:466
964 msgid ""
965 "`include_bin!` : include the contents of the given file as a binary blob"
966 msgstr ""
967
968 #. type: Bullet: '* '
969 #: doc/rust.md:466
970 msgid "`error!`, `warn!`, `info!`, `debug!` : provide diagnostic information."
971 msgstr ""
972
973 #. type: Plain text
974 #: doc/rust.md:469
975 msgid ""
976 "All of the above extensions, with the exception of `proto!`, are expressions "
977 "with values. `proto!` is an item, defining a new name."
978 msgstr ""
979
980 #. type: Plain text
981 #: doc/rust.md:471
982 msgid "## Macros"
983 msgstr ""
984
985 #. type: Plain text
986 #: doc/rust.md:484
987 #, no-wrap
988 msgid ""
989 "expr_macro_rules : \"macro_rules\" '!' ident '(' macro_rule * ')'\n"
990 "macro_rule : '(' matcher * ')' \"=>\" '(' transcriber * ')' ';'\n"
991 "matcher : '(' matcher * ')' | '[' matcher * ']'\n"
992 "        | '{' matcher * '}' | '$' ident ':' ident\n"
993 "        | '$' '(' matcher * ')' sep_token? [ '*' | '+' ]\n"
994 "        | non_special_token\n"
995 "transcriber : '(' transcriber * ')' | '[' transcriber * ']'\n"
996 "            | '{' transcriber * '}' | '$' ident\n"
997 "            | '$' '(' transcriber * ')' sep_token? [ '*' | '+' ]\n"
998 "            | non_special_token\n"
999 msgstr ""
1000
1001 #. type: Plain text
1002 #: doc/rust.md:490
1003 msgid ""
1004 "User-defined syntax extensions are called \"macros\", and the `macro_rules` "
1005 "syntax extension defines them.  Currently, user-defined macros can expand to "
1006 "expressions, statements, or items."
1007 msgstr ""
1008
1009 #. type: Plain text
1010 #: doc/rust.md:493
1011 msgid ""
1012 "(A `sep_token` is any token other than `*` and `+`.  A `non_special_token` "
1013 "is any token other than a delimiter or `$`.)"
1014 msgstr ""
1015
1016 #. type: Plain text
1017 #: doc/rust.md:499
1018 msgid ""
1019 "The macro expander looks up macro invocations by name, and tries each macro "
1020 "rule in turn.  It transcribes the first successful match.  Matching and "
1021 "transcription are closely related to each other, and we will describe them "
1022 "together."
1023 msgstr ""
1024
1025 #. type: Plain text
1026 #: doc/rust.md:501
1027 msgid "### Macro By Example"
1028 msgstr ""
1029
1030 #. type: Plain text
1031 #: doc/rust.md:504
1032 msgid ""
1033 "The macro expander matches and transcribes every token that does not begin "
1034 "with a `$` literally, including delimiters.  For parsing reasons, delimiters "
1035 "must be balanced, but they are otherwise not special."
1036 msgstr ""
1037
1038 #. type: Plain text
1039 #: doc/rust.md:510
1040 msgid ""
1041 "In the matcher, `$` _name_ `:` _designator_ matches the nonterminal in the "
1042 "Rust syntax named by _designator_. Valid designators are `item`, `block`, "
1043 "`stmt`, `pat`, `expr`, `ty` (type), `ident`, `path`, `matchers` (lhs of the "
1044 "`=>` in macro rules), `tt` (rhs of the `=>` in macro rules). In the "
1045 "transcriber, the designator is already known, and so only the name of a "
1046 "matched nonterminal comes after the dollar sign."
1047 msgstr ""
1048
1049 #. type: Plain text
1050 #: doc/rust.md:519
1051 msgid ""
1052 "In both the matcher and transcriber, the Kleene star-like operator indicates "
1053 "repetition.  The Kleene star operator consists of `$` and parens, optionally "
1054 "followed by a separator token, followed by `*` or `+`.  `*` means zero or "
1055 "more repetitions, `+` means at least one repetition.  The parens are not "
1056 "matched or transcribed.  On the matcher side, a name is bound to _all_ of "
1057 "the names it matches, in a structure that mimics the structure of the "
1058 "repetition encountered on a successful match. The job of the transcriber is "
1059 "to sort that structure out."
1060 msgstr ""
1061
1062 #. type: Plain text
1063 #: doc/rust.md:525
1064 msgid ""
1065 "The rules for transcription of these repetitions are called \"Macro By "
1066 "Example\".  Essentially, one \"layer\" of repetition is discharged at a "
1067 "time, and all of them must be discharged by the time a name is transcribed. "
1068 "Therefore, `( $( $i:ident ),* ) => ( $i )` is an invalid macro, but `( $( $i:"
1069 "ident ),* ) => ( $( $i:ident ),* )` is acceptable (if trivial)."
1070 msgstr ""
1071
1072 #. type: Plain text
1073 #: doc/rust.md:533
1074 msgid ""
1075 "When Macro By Example encounters a repetition, it examines all of the `$` "
1076 "_name_ s that occur in its body. At the \"current layer\", they all must "
1077 "repeat the same number of times, so ` ( $( $i:ident ),* ; $( $j:ident ),* ) "
1078 "=> ( $( ($i,$j) ),* )` is valid if given the argument `(a,b,c ; d,e,f)`, but "
1079 "not `(a,b,c ; d,e)`. The repetition walks through the choices at that layer "
1080 "in lockstep, so the former input transcribes to `( (a,d), (b,e), (c,f) )`."
1081 msgstr ""
1082
1083 #. type: Plain text
1084 #: doc/rust.md:535
1085 msgid "Nested repetitions are allowed."
1086 msgstr ""
1087
1088 #. type: Plain text
1089 #: doc/rust.md:537
1090 msgid "### Parsing limitations"
1091 msgstr ""
1092
1093 #. type: Plain text
1094 #: doc/rust.md:540
1095 msgid ""
1096 "The parser used by the macro system is reasonably powerful, but the parsing "
1097 "of Rust syntax is restricted in two ways:"
1098 msgstr ""
1099
1100 #. type: Plain text
1101 #: doc/rust.md:546
1102 #, no-wrap
1103 msgid ""
1104 "1. The parser will always parse as much as possible. If it attempts to match\n"
1105 "`$i:expr [ , ]` against `8 [ , ]`, it will attempt to parse `i` as an array\n"
1106 "index operation and fail. Adding a separator can solve this problem.\n"
1107 "2. The parser must have eliminated all ambiguity by the time it reaches a `$` _name_ `:` _designator_.\n"
1108 "This requirement most often affects name-designator pairs when they occur at the beginning of, or immediately after, a `$(...)*`; requiring a distinctive token in front can solve the problem.\n"
1109 msgstr ""
1110
1111 #. type: Plain text
1112 #: doc/rust.md:549
1113 msgid "## Syntax extensions useful for the macro author"
1114 msgstr ""
1115
1116 #. type: Bullet: '* '
1117 #: doc/rust.md:554
1118 msgid "`log_syntax!` : print out the arguments at compile time"
1119 msgstr ""
1120
1121 #. type: Bullet: '* '
1122 #: doc/rust.md:554
1123 msgid ""
1124 "`trace_macros!` : supply `true` or `false` to enable or disable macro "
1125 "expansion logging"
1126 msgstr ""
1127
1128 #. type: Bullet: '* '
1129 #: doc/rust.md:554
1130 msgid "`stringify!` : turn the identifier argument into a string literal"
1131 msgstr ""
1132
1133 #. type: Bullet: '* '
1134 #: doc/rust.md:554
1135 msgid ""
1136 "`concat_idents!` : create a new identifier by concatenating the arguments"
1137 msgstr ""
1138
1139 #. type: Plain text
1140 #: doc/rust.md:556
1141 msgid "# Crates and source files"
1142 msgstr ""
1143
1144 #. type: Plain text
1145 #: doc/rust.md:563
1146 msgid ""
1147 "Rust is a *compiled* language.  Its semantics obey a *phase distinction* "
1148 "between compile-time and run-time.  Those semantic rules that have a *static "
1149 "interpretation* govern the success or failure of compilation.  We refer to "
1150 "these rules as \"static semantics\".  Semantic rules called \"dynamic "
1151 "semantics\" govern the behavior of programs at run-time.  A program that "
1152 "fails to compile due to violation of a compile-time rule has no defined "
1153 "dynamic semantics; the compiler should halt with an error report, and "
1154 "produce no executable artifact."
1155 msgstr ""
1156
1157 #. type: Plain text
1158 #: doc/rust.md:569
1159 msgid ""
1160 "The compilation model centres on artifacts called _crates_.  Each "
1161 "compilation processes a single crate in source form, and if successful, "
1162 "produces a single crate in binary form: either an executable or a library."
1163 "^[A crate is somewhat analogous to an *assembly* in the ECMA-335 CLI model, "
1164 "a *library* in the SML/NJ Compilation Manager, a *unit* in the Owens and "
1165 "Flatt module system, or a *configuration* in Mesa.]"
1166 msgstr ""
1167
1168 #. type: Plain text
1169 #: doc/rust.md:573
1170 msgid ""
1171 "A _crate_ is a unit of compilation and linking, as well as versioning, "
1172 "distribution and runtime loading.  A crate contains a _tree_ of nested "
1173 "[module](#modules) scopes.  The top level of this tree is a module that is "
1174 "anonymous (from the point of view of paths within the module) and any item "
1175 "within a crate has a canonical [module path](#paths) denoting its location "
1176 "within the crate's module tree."
1177 msgstr ""
1178
1179 #. type: Plain text
1180 #: doc/rust.md:577
1181 msgid ""
1182 "The Rust compiler is always invoked with a single source file as input, and "
1183 "always produces a single output crate.  The processing of that source file "
1184 "may result in other source files being loaded as modules.  Source files have "
1185 "the extension `.rs`."
1186 msgstr ""
1187
1188 #. type: Plain text
1189 #: doc/rust.md:582
1190 msgid ""
1191 "A Rust source file describes a module, the name and location of which -- in "
1192 "the module tree of the current crate -- are defined from outside the source "
1193 "file: either by an explicit `mod_item` in a referencing source file, or by "
1194 "the name of the crate itself."
1195 msgstr ""
1196
1197 #. type: Plain text
1198 #: doc/rust.md:587
1199 msgid ""
1200 "Each source file contains a sequence of zero or more `item` definitions, and "
1201 "may optionally begin with any number of `attributes` that apply to the "
1202 "containing module.  Atributes on the anonymous crate module define important "
1203 "metadata that influences the behavior of the compiler."
1204 msgstr ""
1205
1206 #. type: Plain text
1207 #: doc/rust.md:593
1208 #, no-wrap
1209 msgid ""
1210 "~~~~~~~~\n"
1211 "// Linkage attributes\n"
1212 "#[ link(name = \"projx\",\n"
1213 "        vers = \"2.5\",\n"
1214 "        uuid = \"9cccc5d5-aceb-4af5-8285-811211826b82\") ];\n"
1215 msgstr ""
1216
1217 #. type: Plain text
1218 #: doc/rust.md:598
1219 msgid ""
1220 "// Additional metadata attributes #[ desc = \"Project X\" ]; #[ license = "
1221 "\"BSD\" ]; #[ author = \"Jane Doe\" ];"
1222 msgstr ""
1223
1224 #. type: Plain text
1225 #: doc/rust.md:601
1226 msgid "// Specify the output type #[ crate_type = \"lib\" ];"
1227 msgstr ""
1228
1229 #. type: Plain text
1230 #: doc/rust.md:605
1231 msgid "// Turn on a warning #[ warn(non_camel_case_types) ]; ~~~~~~~~"
1232 msgstr ""
1233
1234 #. type: Plain text
1235 #: doc/rust.md:608
1236 msgid ""
1237 "A crate that contains a `main` function can be compiled to an executable.  "
1238 "If a `main` function is present, its return type must be [`unit`](#primitive-"
1239 "types) and it must take no arguments."
1240 msgstr ""
1241
1242 #. type: Plain text
1243 #: doc/rust.md:611
1244 msgid "# Items and attributes"
1245 msgstr ""
1246
1247 #. type: Plain text
1248 #: doc/rust.md:614
1249 msgid ""
1250 "Crates contain [items](#items), each of which may have some number of "
1251 "[attributes](#attributes) attached to it."
1252 msgstr ""
1253
1254 #. type: Plain text
1255 #: doc/rust.md:616
1256 msgid "## Items"
1257 msgstr ""
1258
1259 #. type: Plain text
1260 #: doc/rust.md:621
1261 #, no-wrap
1262 msgid ""
1263 "~~~~~~~~ {.ebnf .gram}\n"
1264 "item : mod_item | fn_item | type_item | struct_item | enum_item\n"
1265 "     | static_item | trait_item | impl_item | extern_block ;\n"
1266 "~~~~~~~~\n"
1267 msgstr ""
1268
1269 #. type: Plain text
1270 #: doc/rust.md:627
1271 msgid ""
1272 "An _item_ is a component of a crate; some module items can be defined in "
1273 "crate files, but most are defined in source files. Items are organized "
1274 "within a crate by a nested set of [modules](#modules). Every crate has a "
1275 "single \"outermost\" anonymous module; all further items within the crate "
1276 "have [paths](#paths) within the module tree of the crate."
1277 msgstr ""
1278
1279 #. type: Plain text
1280 #: doc/rust.md:630
1281 msgid ""
1282 "Items are entirely determined at compile-time, generally remain fixed during "
1283 "execution, and may reside in read-only memory."
1284 msgstr ""
1285
1286 #. type: Plain text
1287 #: doc/rust.md:632
1288 msgid "There are several kinds of item:"
1289 msgstr ""
1290
1291 #. type: Bullet: '  * '
1292 #: doc/rust.md:641
1293 msgid "[modules](#modules)"
1294 msgstr ""
1295
1296 #. type: Bullet: '  * '
1297 #: doc/rust.md:641
1298 msgid "[functions](#functions)"
1299 msgstr ""
1300
1301 #. type: Bullet: '  * '
1302 #: doc/rust.md:641
1303 msgid "[type definitions](#type-definitions)"
1304 msgstr ""
1305
1306 #. type: Bullet: '  * '
1307 #: doc/rust.md:641
1308 msgid "[structures](#structures)"
1309 msgstr ""
1310
1311 #. type: Bullet: '  * '
1312 #: doc/rust.md:641
1313 msgid "[enumerations](#enumerations)"
1314 msgstr ""
1315
1316 #. type: Bullet: '  * '
1317 #: doc/rust.md:641
1318 msgid "[static items](#static-items)"
1319 msgstr ""
1320
1321 #. type: Bullet: '  * '
1322 #: doc/rust.md:641
1323 msgid "[traits](#traits)"
1324 msgstr ""
1325
1326 #. type: Bullet: '  * '
1327 #: doc/rust.md:641
1328 msgid "[implementations](#implementations)"
1329 msgstr ""
1330
1331 #. type: Plain text
1332 #: doc/rust.md:651
1333 msgid ""
1334 "Some items form an implicit scope for the declaration of sub-items. In other "
1335 "words, within a function or module, declarations of items can (in many "
1336 "cases)  be mixed with the statements, control blocks, and similar artifacts "
1337 "that otherwise compose the item body. The meaning of these scoped items is "
1338 "the same as if the item was declared outside the scope -- it is still a "
1339 "static item -- except that the item's *path name* within the module "
1340 "namespace is qualified by the name of the enclosing item, or is private to "
1341 "the enclosing item (in the case of functions).  The grammar specifies the "
1342 "exact locations in which sub-item declarations may appear."
1343 msgstr ""
1344
1345 #. type: Plain text
1346 #: doc/rust.md:653
1347 msgid "### Type Parameters"
1348 msgstr ""
1349
1350 #. type: Plain text
1351 #: doc/rust.md:662
1352 msgid ""
1353 "All items except modules may be *parameterized* by type. Type parameters are "
1354 "given as a comma-separated list of identifiers enclosed in angle brackets "
1355 "(`<...>`), after the name of the item and before its definition.  The type "
1356 "parameters of an item are considered \"part of the name\", not part of the "
1357 "type of the item.  A referencing [path](#paths) must (in principle) provide "
1358 "type arguments as a list of comma-separated types enclosed within angle "
1359 "brackets, in order to refer to the type-parameterized item.  In practice, "
1360 "the type-inference system can usually infer such argument types from "
1361 "context.  There are no general type-parametric types, only type-parametric "
1362 "items.  That is, Rust has no notion of type abstraction: there are no first-"
1363 "class \"forall\" types."
1364 msgstr ""
1365
1366 #. type: Plain text
1367 #: doc/rust.md:664
1368 msgid "### Modules"
1369 msgstr ""
1370
1371 #. type: Plain text
1372 #: doc/rust.md:669
1373 msgid ""
1374 "~~~~~~~~ {.ebnf .gram} mod_item : \"mod\" ident ( ';' | '{' mod '}' ); mod : "
1375 "[ view_item | item ] * ; ~~~~~~~~"
1376 msgstr ""
1377
1378 #. type: Plain text
1379 #: doc/rust.md:674
1380 msgid ""
1381 "A module is a container for zero or more [view items](#view-items) and zero "
1382 "or more [items](#items). The view items manage the visibility of the items "
1383 "defined within the module, as well as the visibility of names from outside "
1384 "the module when referenced from inside the module."
1385 msgstr ""
1386
1387 #. type: Plain text
1388 #: doc/rust.md:678
1389 msgid ""
1390 "A _module item_ is a module, surrounded in braces, named, and prefixed with "
1391 "the keyword `mod`. A module item introduces a new, named module into the "
1392 "tree of modules making up a crate. Modules can nest arbitrarily."
1393 msgstr ""
1394
1395 #. type: Plain text
1396 #: doc/rust.md:680
1397 msgid "An example of a module:"
1398 msgstr ""
1399
1400 #. type: Plain text
1401 #: doc/rust.md:698
1402 #, no-wrap
1403 msgid ""
1404 "~~~~~~~~\n"
1405 "mod math {\n"
1406 "    type complex = (f64, f64);\n"
1407 "    fn sin(f: f64) -> f64 {\n"
1408 "        ...\n"
1409 "# fail!();\n"
1410 "    }\n"
1411 "    fn cos(f: f64) -> f64 {\n"
1412 "        ...\n"
1413 "# fail!();\n"
1414 "    }\n"
1415 "    fn tan(f: f64) -> f64 {\n"
1416 "        ...\n"
1417 "# fail!();\n"
1418 "    }\n"
1419 "}\n"
1420 "~~~~~~~~\n"
1421 msgstr ""
1422
1423 #. type: Plain text
1424 #: doc/rust.md:703
1425 msgid ""
1426 "Modules and types share the same namespace.  Declaring a named type that has "
1427 "the same name as a module in scope is forbidden: that is, a type definition, "
1428 "trait, struct, enumeration, or type parameter can't shadow the name of a "
1429 "module in scope, or vice versa."
1430 msgstr ""
1431
1432 #. type: Plain text
1433 #: doc/rust.md:708
1434 msgid ""
1435 "A module without a body is loaded from an external file, by default with the "
1436 "same name as the module, plus the `.rs` extension.  When a nested submodule "
1437 "is loaded from an external file, it is loaded from a subdirectory path that "
1438 "mirrors the module hierarchy."
1439 msgstr ""
1440
1441 #. type: Plain text
1442 #: doc/rust.md:712
1443 msgid "~~~ {.xfail-test} // Load the `vec` module from `vec.rs` mod vec;"
1444 msgstr ""
1445
1446 #. type: Plain text
1447 #: doc/rust.md:718
1448 #, no-wrap
1449 msgid ""
1450 "mod task {\n"
1451 "    // Load the `local_data` module from `task/local_data.rs`\n"
1452 "    mod local_data;\n"
1453 "}\n"
1454 "~~~\n"
1455 msgstr ""
1456
1457 #. type: Plain text
1458 #: doc/rust.md:721
1459 msgid ""
1460 "The directories and files used for loading external file modules can be "
1461 "influenced with the `path` attribute."
1462 msgstr ""
1463
1464 #. type: Plain text
1465 #: doc/rust.md:730
1466 #, no-wrap
1467 msgid ""
1468 "~~~ {.xfail-test}\n"
1469 "#[path = \"task_files\"]\n"
1470 "mod task {\n"
1471 "    // Load the `local_data` module from `task_files/tls.rs`\n"
1472 "    #[path = \"tls.rs\"]\n"
1473 "    mod local_data;\n"
1474 "}\n"
1475 "~~~\n"
1476 msgstr ""
1477
1478 #. type: Plain text
1479 #: doc/rust.md:732
1480 msgid "#### View items"
1481 msgstr ""
1482
1483 #. type: Plain text
1484 #: doc/rust.md:736
1485 msgid ""
1486 "~~~~~~~~ {.ebnf .gram} view_item : extern_mod_decl | use_decl ; ~~~~~~~~"
1487 msgstr ""
1488
1489 #. type: Plain text
1490 #: doc/rust.md:740
1491 msgid ""
1492 "A view item manages the namespace of a module.  View items do not define new "
1493 "items, but rather, simply change other items' visibility.  There are several "
1494 "kinds of view item:"
1495 msgstr ""
1496
1497 #. type: Bullet: ' * '
1498 #: doc/rust.md:743
1499 msgid "[`extern mod` declarations](#extern-mod-declarations)"
1500 msgstr ""
1501
1502 #. type: Bullet: ' * '
1503 #: doc/rust.md:743
1504 msgid "[`use` declarations](#use-declarations)"
1505 msgstr ""
1506
1507 #. type: Plain text
1508 #: doc/rust.md:745
1509 msgid "##### Extern mod declarations"
1510 msgstr ""
1511
1512 #. type: Plain text
1513 #: doc/rust.md:751
1514 msgid ""
1515 "~~~~~~~~ {.ebnf .gram} extern_mod_decl : \"extern\" \"mod\" ident [ '(' "
1516 "link_attrs ')' ] ? [ '=' string_lit ] ? ; link_attrs : link_attr [ ',' "
1517 "link_attrs ] + ; link_attr : ident '=' literal ; ~~~~~~~~"
1518 msgstr ""
1519
1520 #. type: Plain text
1521 #: doc/rust.md:755
1522 msgid ""
1523 "An _`extern mod` declaration_ specifies a dependency on an external crate.  "
1524 "The external crate is then bound into the declaring scope as the `ident` "
1525 "provided in the `extern_mod_decl`."
1526 msgstr ""
1527
1528 #. type: Plain text
1529 #: doc/rust.md:765
1530 msgid ""
1531 "The external crate is resolved to a specific `soname` at compile time, and a "
1532 "runtime linkage requirement to that `soname` is passed to the linker for "
1533 "loading at runtime.  The `soname` is resolved at compile time by scanning "
1534 "the compiler's library path and matching the `link_attrs` provided in the "
1535 "`use_decl` against any `#link` attributes that were declared on the external "
1536 "crate when it was compiled.  If no `link_attrs` are provided, a default "
1537 "`name` attribute is assumed, equal to the `ident` given in the `use_decl`."
1538 msgstr ""
1539
1540 #. type: Plain text
1541 #: doc/rust.md:775
1542 msgid ""
1543 "Optionally, an identifier in an `extern mod` declaration may be followed by "
1544 "an equals sign, then a string literal denoting a relative path on the "
1545 "filesystem.  This path should exist in one of the directories in the Rust "
1546 "path, which by default contains the `.rust` subdirectory of the current "
1547 "directory and each of its parents, as well as any directories in the colon-"
1548 "separated (or semicolon-separated on Windows)  list of paths that is the "
1549 "`RUST_PATH` environment variable.  The meaning of `extern mod a = \"b/c/d\";"
1550 "`, supposing that `/a` is in the RUST_PATH, is that the name `a` should be "
1551 "taken as a reference to the crate whose absolute location is `/a/b/c/d`."
1552 msgstr ""
1553
1554 #. type: Plain text
1555 #: doc/rust.md:777
1556 msgid "Four examples of `extern mod` declarations:"
1557 msgstr ""
1558
1559 #. type: Plain text
1560 #: doc/rust.md:780
1561 msgid ""
1562 "~~~~~~~~{.xfail-test} extern mod pcre (uuid = \"54aba0f8-"
1563 "a7b1-4beb-92f1-4cf625264841\");"
1564 msgstr ""
1565
1566 #. type: Plain text
1567 #: doc/rust.md:782
1568 msgid ""
1569 "extern mod extra; // equivalent to: extern mod extra ( name = \"extra\" );"
1570 msgstr ""
1571
1572 #. type: Plain text
1573 #: doc/rust.md:784
1574 msgid ""
1575 "extern mod rustextra (name = \"extra\"); // linking to 'extra' under another "
1576 "name"
1577 msgstr ""
1578
1579 #. type: Plain text
1580 #: doc/rust.md:787
1581 msgid "extern mod complicated_mod = \"some-file/in/the-rust/path\"; ~~~~~~~~"
1582 msgstr ""
1583
1584 #. type: Plain text
1585 #: doc/rust.md:789
1586 msgid "##### Use declarations"
1587 msgstr ""
1588
1589 #. type: Plain text
1590 #: doc/rust.md:793
1591 #, no-wrap
1592 msgid ""
1593 "~~~~~~~~ {.ebnf .gram}\n"
1594 "use_decl : \"pub\"? \"use\" ident [ '=' path\n"
1595 "                          | \"::\" path_glob ] ;\n"
1596 msgstr ""
1597
1598 #. type: Plain text
1599 #: doc/rust.md:798
1600 #, no-wrap
1601 msgid ""
1602 "path_glob : ident [ \"::\" path_glob ] ?\n"
1603 "          | '*'\n"
1604 "          | '{' ident [ ',' ident ] * '}'\n"
1605 "~~~~~~~~\n"
1606 msgstr ""
1607
1608 #. type: Plain text
1609 #: doc/rust.md:802
1610 msgid ""
1611 "A _use declaration_ creates one or more local name bindings synonymous with "
1612 "some other [path](#paths).  Usually a `use` declaration is used to shorten "
1613 "the path required to refer to a module item."
1614 msgstr ""
1615
1616 #. type: Plain text
1617 #: doc/rust.md:806
1618 #, no-wrap
1619 msgid ""
1620 "*Note*: Unlike in many languages,\n"
1621 "`use` declarations in Rust do *not* declare linkage dependency with external crates.\n"
1622 "Rather, [`extern mod` declarations](#extern-mod-declarations) declare linkage dependencies.\n"
1623 msgstr ""
1624
1625 #. type: Plain text
1626 #: doc/rust.md:808
1627 msgid "Use declarations support a number of convenient shortcuts:"
1628 msgstr ""
1629
1630 #. type: Bullet: '  * '
1631 #: doc/rust.md:813
1632 msgid ""
1633 "Rebinding the target name as a new local name, using the syntax `use x = p::"
1634 "q::r;`."
1635 msgstr ""
1636
1637 #. type: Bullet: '  * '
1638 #: doc/rust.md:813
1639 msgid ""
1640 "Simultaneously binding a list of paths differing only in their final "
1641 "element, using the glob-like brace syntax `use a::b::{c,d,e,f};`"
1642 msgstr ""
1643
1644 #. type: Bullet: '  * '
1645 #: doc/rust.md:813
1646 msgid ""
1647 "Binding all paths matching a given prefix, using the asterisk wildcard "
1648 "syntax `use a::b::*;`"
1649 msgstr ""
1650
1651 #. type: Plain text
1652 #: doc/rust.md:815
1653 msgid "An example of `use` declarations:"
1654 msgstr ""
1655
1656 #. type: Plain text
1657 #: doc/rust.md:819
1658 msgid "~~~~ use std::num::sin; use std::option::{Some, None};"
1659 msgstr ""
1660
1661 #. type: Plain text
1662 #: doc/rust.md:823
1663 #, no-wrap
1664 msgid ""
1665 "fn main() {\n"
1666 "    // Equivalent to 'info!(std::num::sin(1.0));'\n"
1667 "    info!(sin(1.0));\n"
1668 msgstr ""
1669
1670 #. type: Plain text
1671 #: doc/rust.md:828
1672 #, no-wrap
1673 msgid ""
1674 "    // Equivalent to 'info!(~[std::option::Some(1.0), std::option::None]);'\n"
1675 "    info!(~[Some(1.0), None]);\n"
1676 "}\n"
1677 "~~~~\n"
1678 msgstr ""
1679
1680 #. type: Plain text
1681 #: doc/rust.md:836
1682 msgid ""
1683 "Like items, `use` declarations are private to the containing module, by "
1684 "default.  Also like items, a `use` declaration can be public, if qualified "
1685 "by the `pub` keyword.  Such a `use` declaration serves to _re-export_ a "
1686 "name.  A public `use` declaration can therefore _redirect_ some public name "
1687 "to a different target definition: even a definition with a private canonical "
1688 "path, inside a different module.  If a sequence of such redirections form a "
1689 "cycle or cannot be resolved unambiguously, they represent a compile-time "
1690 "error."
1691 msgstr ""
1692
1693 #. type: Plain text
1694 #: doc/rust.md:842
1695 #, no-wrap
1696 msgid ""
1697 "An example of re-exporting:\n"
1698 "~~~~\n"
1699 "# fn main() { }\n"
1700 "mod quux {\n"
1701 "    pub use quux::foo::*;\n"
1702 msgstr ""
1703
1704 #. type: Plain text
1705 #: doc/rust.md:849
1706 #, no-wrap
1707 msgid ""
1708 "    pub mod foo {\n"
1709 "        pub fn bar() { }\n"
1710 "        pub fn baz() { }\n"
1711 "    }\n"
1712 "}\n"
1713 "~~~~\n"
1714 msgstr ""
1715
1716 #. type: Plain text
1717 #: doc/rust.md:851
1718 msgid ""
1719 "In this example, the module `quux` re-exports all of the public names "
1720 "defined in `foo`."
1721 msgstr ""
1722
1723 #. type: Plain text
1724 #: doc/rust.md:854
1725 msgid ""
1726 "Also note that the paths contained in `use` items are relative to the crate "
1727 "root.  So, in the previous example, the `use` refers to `quux::foo::*`, and "
1728 "not simply to `foo::*`."
1729 msgstr ""
1730
1731 #. type: Plain text
1732 #: doc/rust.md:856
1733 msgid "### Functions"
1734 msgstr ""
1735
1736 #. type: Plain text
1737 #: doc/rust.md:860
1738 msgid ""
1739 "A _function item_ defines a sequence of [statements](#statements) and an "
1740 "optional final [expression](#expressions), along with a name and a set of "
1741 "parameters.  Functions are declared with the keyword `fn`.  Functions "
1742 "declare a set of *input* [*slots*](#memory-slots) as parameters, through "
1743 "which the caller passes arguments into the function, and an *output* [*slot*]"
1744 "(#memory-slots) through which the function passes results back to the caller."
1745 msgstr ""
1746
1747 #. type: Plain text
1748 #: doc/rust.md:865
1749 msgid ""
1750 "A function may also be copied into a first class *value*, in which case the "
1751 "value has the corresponding [*function type*](#function-types), and can be "
1752 "used otherwise exactly as a function item (with a minor additional cost of "
1753 "calling the function indirectly)."
1754 msgstr ""
1755
1756 #. type: Plain text
1757 #: doc/rust.md:871
1758 msgid ""
1759 "Every control path in a function logically ends with a `return` expression "
1760 "or a diverging expression. If the outermost block of a function has a value-"
1761 "producing expression in its final-expression position, that expression is "
1762 "interpreted as an implicit `return` expression applied to the final-"
1763 "expression."
1764 msgstr ""
1765
1766 #. type: Plain text
1767 #: doc/rust.md:873
1768 msgid "An example of a function:"
1769 msgstr ""
1770
1771 #. type: Plain text
1772 #: doc/rust.md:879
1773 #, no-wrap
1774 msgid ""
1775 "~~~~\n"
1776 "fn add(x: int, y: int) -> int {\n"
1777 "    return x + y;\n"
1778 "}\n"
1779 "~~~~\n"
1780 msgstr ""
1781
1782 #. type: Plain text
1783 #: doc/rust.md:882
1784 msgid ""
1785 "As with `let` bindings, function arguments are irrefutable patterns, so any "
1786 "pattern that is valid in a let binding is also valid as an argument."
1787 msgstr ""
1788
1789 #. type: Plain text
1790 #: doc/rust.md:886
1791 msgid "~~~ fn first((value, _): (int, int)) -> int { value } ~~~"
1792 msgstr ""
1793
1794 #. type: Plain text
1795 #: doc/rust.md:889
1796 msgid "#### Generic functions"
1797 msgstr ""
1798
1799 #. type: Plain text
1800 #: doc/rust.md:894
1801 msgid ""
1802 "A _generic function_ allows one or more _parameterized types_ to appear in "
1803 "its signature. Each type parameter must be explicitly declared, in an angle-"
1804 "bracket-enclosed, comma-separated list following the function name."
1805 msgstr ""
1806
1807 #. type: Plain text
1808 #: doc/rust.md:905
1809 #, no-wrap
1810 msgid ""
1811 "~~~~ {.xfail-test}\n"
1812 "fn iter<T>(seq: &[T], f: &fn(T)) {\n"
1813 "    for elt in seq.iter() { f(elt); }\n"
1814 "}\n"
1815 "fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {\n"
1816 "    let mut acc = ~[];\n"
1817 "    for elt in seq.iter() { acc.push(f(elt)); }\n"
1818 "    acc\n"
1819 "}\n"
1820 "~~~~\n"
1821 msgstr ""
1822
1823 #. type: Plain text
1824 #: doc/rust.md:908
1825 msgid ""
1826 "Inside the function signature and body, the name of the type parameter can "
1827 "be used as a type name."
1828 msgstr ""
1829
1830 #. type: Plain text
1831 #: doc/rust.md:914
1832 msgid ""
1833 "When a generic function is referenced, its type is instantiated based on the "
1834 "context of the reference. For example, calling the `iter` function defined "
1835 "above on `[1, 2]` will instantiate type parameter `T` with `int`, and "
1836 "require the closure parameter to have type `fn(int)`."
1837 msgstr ""
1838
1839 #. type: Plain text
1840 #: doc/rust.md:919
1841 msgid ""
1842 "The type parameters can also be explicitly supplied in a trailing [path]"
1843 "(#paths) component after the function name. This might be necessary if there "
1844 "is not sufficient context to determine the type parameters. For example, "
1845 "`sys::size_of::<u32>() == 4`."
1846 msgstr ""
1847
1848 #. type: Plain text
1849 #: doc/rust.md:923
1850 msgid ""
1851 "Since a parameter type is opaque to the generic function, the set of "
1852 "operations that can be performed on it is limited. Values of parameter type "
1853 "can only be moved, not copied."
1854 msgstr ""
1855
1856 #. type: Plain text
1857 #: doc/rust.md:927
1858 msgid "~~~~ fn id<T>(x: T) -> T { x } ~~~~"
1859 msgstr ""
1860
1861 #. type: Plain text
1862 #: doc/rust.md:931
1863 msgid ""
1864 "Similarly, [trait](#traits) bounds can be specified for type parameters to "
1865 "allow methods with that trait to be called on values of that type."
1866 msgstr ""
1867
1868 #. type: Plain text
1869 #: doc/rust.md:934
1870 msgid "#### Unsafe functions"
1871 msgstr ""
1872
1873 #. type: Plain text
1874 #: doc/rust.md:937
1875 msgid ""
1876 "Unsafe functions are those containing unsafe operations that are not "
1877 "contained in an [`unsafe` block](#unsafe-blocks).  Such a function must be "
1878 "prefixed with the keyword `unsafe`."
1879 msgstr ""
1880
1881 #. type: Plain text
1882 #: doc/rust.md:940
1883 msgid ""
1884 "Unsafe operations are those that potentially violate the memory-safety "
1885 "guarantees of Rust's static semantics.  Specifically, the following "
1886 "operations are considered unsafe:"
1887 msgstr ""
1888
1889 #. type: Bullet: '  - '
1890 #: doc/rust.md:944
1891 msgid "Dereferencing a [raw pointer](#pointer-types)."
1892 msgstr ""
1893
1894 #. type: Bullet: '  - '
1895 #: doc/rust.md:944
1896 msgid "Casting a [raw pointer](#pointer-types) to a safe pointer type."
1897 msgstr ""
1898
1899 #. type: Bullet: '  - '
1900 #: doc/rust.md:944
1901 msgid "Calling an unsafe function."
1902 msgstr ""
1903
1904 #. type: Plain text
1905 #: doc/rust.md:946
1906 msgid "##### Unsafe blocks"
1907 msgstr ""
1908
1909 #. type: Plain text
1910 #: doc/rust.md:950
1911 msgid ""
1912 "A block of code can also be prefixed with the `unsafe` keyword, to permit a "
1913 "sequence of unsafe operations in an otherwise-safe function.  This facility "
1914 "exists because the static semantics of Rust are a necessary approximation of "
1915 "the dynamic semantics.  When a programmer has sufficient conviction that a "
1916 "sequence of unsafe operations is actually safe, they can encapsulate that "
1917 "sequence (taken as a whole) within an `unsafe` block. The compiler will "
1918 "consider uses of such code \"safe\", to the surrounding context."
1919 msgstr ""
1920
1921 #. type: Plain text
1922 #: doc/rust.md:953
1923 msgid "#### Diverging functions"
1924 msgstr ""
1925
1926 #. type: Plain text
1927 #: doc/rust.md:956
1928 msgid ""
1929 "A special kind of function can be declared with a `!` character where the "
1930 "output slot type would normally be. For example:"
1931 msgstr ""
1932
1933 #. type: Plain text
1934 #: doc/rust.md:963
1935 #, no-wrap
1936 msgid ""
1937 "~~~~\n"
1938 "fn my_err(s: &str) -> ! {\n"
1939 "    info!(s);\n"
1940 "    fail!();\n"
1941 "}\n"
1942 "~~~~\n"
1943 msgstr ""
1944
1945 #. type: Plain text
1946 #: doc/rust.md:970
1947 msgid ""
1948 "We call such functions \"diverging\" because they never return a value to "
1949 "the caller. Every control path in a diverging function must end with a `fail!"
1950 "()` or a call to another diverging function on every control path. The `!` "
1951 "annotation does *not* denote a type. Rather, the result type of a diverging "
1952 "function is a special type called $\\bot$ (\"bottom\") that unifies with any "
1953 "type. Rust has no syntax for $\\bot$."
1954 msgstr ""
1955
1956 #. type: Plain text
1957 #: doc/rust.md:976
1958 msgid ""
1959 "It might be necessary to declare a diverging function because as mentioned "
1960 "previously, the typechecker checks that every control path in a function "
1961 "ends with a [`return`](#return-expressions) or diverging expression. So, if "
1962 "`my_err` were declared without the `!` annotation, the following code would "
1963 "not typecheck:"
1964 msgstr ""
1965
1966 #. type: Plain text
1967 #: doc/rust.md:979
1968 msgid "~~~~ # fn my_err(s: &str) -> ! { fail!() }"
1969 msgstr ""
1970
1971 #. type: Plain text
1972 #: doc/rust.md:989
1973 #, no-wrap
1974 msgid ""
1975 "fn f(i: int) -> int {\n"
1976 "   if i == 42 {\n"
1977 "     return 42;\n"
1978 "   }\n"
1979 "   else {\n"
1980 "     my_err(\"Bad number!\");\n"
1981 "   }\n"
1982 "}\n"
1983 "~~~~\n"
1984 msgstr ""
1985
1986 #. type: Plain text
1987 #: doc/rust.md:997
1988 msgid ""
1989 "This will not compile without the `!` annotation on `my_err`, since the "
1990 "`else` branch of the conditional in `f` does not return an `int`, as "
1991 "required by the signature of `f`.  Adding the `!` annotation to `my_err` "
1992 "informs the typechecker that, should control ever enter `my_err`, no further "
1993 "type judgments about `f` need to hold, since control will never resume in "
1994 "any context that relies on those judgments.  Thus the return type on `f` "
1995 "only needs to reflect the `if` branch of the conditional."
1996 msgstr ""
1997
1998 #. type: Plain text
1999 #: doc/rust.md:1000
2000 msgid "#### Extern functions"
2001 msgstr ""
2002
2003 #. type: Plain text
2004 #: doc/rust.md:1007
2005 msgid ""
2006 "Extern functions are part of Rust's foreign function interface, providing "
2007 "the opposite functionality to [external blocks](#external-blocks).  Whereas "
2008 "external blocks allow Rust code to call foreign code, extern functions with "
2009 "bodies defined in Rust code _can be called by foreign code_. They are "
2010 "defined in the same way as any other Rust function, except that they have "
2011 "the `extern` modifier."
2012 msgstr ""
2013
2014 #. type: Plain text
2015 #: doc/rust.md:1011
2016 msgid "~~~ extern fn new_vec() -> ~[int] { ~[] } ~~~"
2017 msgstr ""
2018
2019 #. type: Plain text
2020 #: doc/rust.md:1014
2021 msgid ""
2022 "Extern functions may not be called from Rust code, but Rust code may take "
2023 "their value as a raw `u8` pointer."
2024 msgstr ""
2025
2026 #. type: Plain text
2027 #: doc/rust.md:1019
2028 msgid ""
2029 "~~~ # extern fn new_vec() -> ~[int] { ~[] } let fptr: *u8 = new_vec; ~~~"
2030 msgstr ""
2031
2032 #. type: Plain text
2033 #: doc/rust.md:1023
2034 msgid ""
2035 "The primary motivation for extern functions is to create callbacks for "
2036 "foreign functions that expect to receive function pointers."
2037 msgstr ""
2038
2039 #. type: Plain text
2040 #: doc/rust.md:1025
2041 msgid "### Type definitions"
2042 msgstr ""
2043
2044 #. type: Plain text
2045 #: doc/rust.md:1029
2046 msgid ""
2047 "A _type definition_ defines a new name for an existing [type](#types). Type "
2048 "definitions are declared with the keyword `type`. Every value has a single, "
2049 "specific type; the type-specified aspects of a value include:"
2050 msgstr ""
2051
2052 #. type: Bullet: '* '
2053 #: doc/rust.md:1035
2054 msgid "Whether the value is composed of sub-values or is indivisible."
2055 msgstr ""
2056
2057 #. type: Bullet: '* '
2058 #: doc/rust.md:1035
2059 msgid "Whether the value represents textual or numerical information."
2060 msgstr ""
2061
2062 #. type: Bullet: '* '
2063 #: doc/rust.md:1035
2064 msgid "Whether the value represents integral or floating-point information."
2065 msgstr ""
2066
2067 #. type: Bullet: '* '
2068 #: doc/rust.md:1035
2069 msgid "The sequence of memory operations required to access the value."
2070 msgstr ""
2071
2072 #. type: Bullet: '* '
2073 #: doc/rust.md:1035
2074 msgid "The [kind](#type-kinds) of the type."
2075 msgstr ""
2076
2077 #. type: Plain text
2078 #: doc/rust.md:1038
2079 msgid ""
2080 "For example, the type `(u8, u8)` defines the set of immutable values that "
2081 "are composite pairs, each containing two unsigned 8-bit integers accessed by "
2082 "pattern-matching and laid out in memory with the `x` component preceding the "
2083 "`y` component."
2084 msgstr ""
2085
2086 #. type: Plain text
2087 #: doc/rust.md:1040
2088 msgid "### Structures"
2089 msgstr ""
2090
2091 #. type: Plain text
2092 #: doc/rust.md:1042
2093 msgid ""
2094 "A _structure_ is a nominal [structure type](#structure-types) defined with "
2095 "the keyword `struct`."
2096 msgstr ""
2097
2098 #. type: Plain text
2099 #: doc/rust.md:1044
2100 msgid "An example of a `struct` item and its use:"
2101 msgstr ""
2102
2103 #. type: Plain text
2104 #: doc/rust.md:1050
2105 msgid ""
2106 "~~~~ struct Point {x: int, y: int} let p = Point {x: 10, y: 11}; let px: int "
2107 "= p.x; ~~~~"
2108 msgstr ""
2109
2110 #. type: Plain text
2111 #: doc/rust.md:1053
2112 msgid ""
2113 "A _tuple structure_ is a nominal [tuple type](#tuple-types), also defined "
2114 "with the keyword `struct`.  For example:"
2115 msgstr ""
2116
2117 #. type: Plain text
2118 #: doc/rust.md:1059
2119 msgid ""
2120 "~~~~ struct Point(int, int); let p = Point(10, 11); let px: int = match p "
2121 "{ Point(x, _) => x }; ~~~~"
2122 msgstr ""
2123
2124 #. type: Plain text
2125 #: doc/rust.md:1063
2126 msgid ""
2127 "A _unit-like struct_ is a structure without any fields, defined by leaving "
2128 "off the list of fields entirely.  Such types will have a single value, just "
2129 "like the [unit value `()`](#unit-and-boolean-literals) of the unit type.  "
2130 "For example:"
2131 msgstr ""
2132
2133 #. type: Plain text
2134 #: doc/rust.md:1068
2135 msgid "~~~~ struct Cookie; let c = [Cookie, Cookie, Cookie, Cookie]; ~~~~"
2136 msgstr ""
2137
2138 #. type: Plain text
2139 #: doc/rust.md:1070
2140 msgid "### Enumerations"
2141 msgstr ""
2142
2143 #. type: Plain text
2144 #: doc/rust.md:1073
2145 msgid ""
2146 "An _enumeration_ is a simultaneous definition of a nominal [enumerated type]"
2147 "(#enumerated-types) as well as a set of *constructors*, that can be used to "
2148 "create or pattern-match values of the corresponding enumerated type."
2149 msgstr ""
2150
2151 #. type: Plain text
2152 #: doc/rust.md:1075
2153 msgid "Enumerations are declared with the keyword `enum`."
2154 msgstr ""
2155
2156 #. type: Plain text
2157 #: doc/rust.md:1077
2158 msgid "An example of an `enum` item and its use:"
2159 msgstr ""
2160
2161 #. type: Plain text
2162 #: doc/rust.md:1083
2163 #, no-wrap
2164 msgid ""
2165 "~~~~\n"
2166 "enum Animal {\n"
2167 "  Dog,\n"
2168 "  Cat\n"
2169 "}\n"
2170 msgstr ""
2171
2172 #. type: Plain text
2173 #: doc/rust.md:1087
2174 msgid "let mut a: Animal = Dog; a = Cat; ~~~~"
2175 msgstr ""
2176
2177 #. type: Plain text
2178 #: doc/rust.md:1094
2179 #, no-wrap
2180 msgid ""
2181 "Enumeration constructors can have either named or unnamed fields:\n"
2182 "~~~~\n"
2183 "enum Animal {\n"
2184 "    Dog (~str, float),\n"
2185 "    Cat { name: ~str, weight: float }\n"
2186 "}\n"
2187 msgstr ""
2188
2189 #. type: Plain text
2190 #: doc/rust.md:1098
2191 msgid ""
2192 "let mut a: Animal = Dog(~\"Cocoa\", 37.2); a = Cat{ name: ~\"Spotty\", "
2193 "weight: 2.7 }; ~~~~"
2194 msgstr ""
2195
2196 #. type: Plain text
2197 #: doc/rust.md:1101
2198 msgid ""
2199 "In this example, `Cat` is a _struct-like enum variant_, whereas `Dog` is "
2200 "simply called an enum variant."
2201 msgstr ""
2202
2203 #. type: Plain text
2204 #: doc/rust.md:1103
2205 msgid "### Static items"
2206 msgstr ""
2207
2208 #. type: Plain text
2209 #: doc/rust.md:1107
2210 msgid ""
2211 "~~~~~~~~ {.ebnf .gram} static_item : \"static\" ident ':' type '=' expr "
2212 "';' ; ~~~~~~~~"
2213 msgstr ""
2214
2215 #. type: Plain text
2216 #: doc/rust.md:1114
2217 msgid ""
2218 "A *static item* is a named _constant value_ stored in the global data "
2219 "section of a crate.  Immutable static items are stored in the read-only data "
2220 "section.  The constant value bound to a static item is, like all constant "
2221 "values, evaluated at compile time.  Static items have the `static` lifetime, "
2222 "which outlives all other lifetimes in a Rust program.  Static items are "
2223 "declared with the `static` keyword.  A static item must have a _constant "
2224 "expression_ giving its definition."
2225 msgstr ""
2226
2227 #. type: Plain text
2228 #: doc/rust.md:1119
2229 msgid ""
2230 "Static items must be explicitly typed.  The type may be ```bool```, "
2231 "```char```, a number, or a type derived from those primitive types.  The "
2232 "derived types are borrowed pointers with the `'static` lifetime, fixed-size "
2233 "arrays, tuples, and structs."
2234 msgstr ""
2235
2236 #. type: Plain text
2237 #: doc/rust.md:1123
2238 msgid "~~~~ static BIT1: uint = 1 << 0; static BIT2: uint = 1 << 1;"
2239 msgstr ""
2240
2241 #. type: Plain text
2242 #: doc/rust.md:1126
2243 msgid ""
2244 "static BITS: [uint, ..2] = [BIT1, BIT2]; static STRING: &'static str = "
2245 "\"bitstring\";"
2246 msgstr ""
2247
2248 #. type: Plain text
2249 #: doc/rust.md:1131
2250 #, no-wrap
2251 msgid ""
2252 "struct BitsNStrings<'self> {\n"
2253 "    mybits: [uint, ..2],\n"
2254 "    mystring: &'self str\n"
2255 "}\n"
2256 msgstr ""
2257
2258 #. type: Plain text
2259 #: doc/rust.md:1137
2260 #, no-wrap
2261 msgid ""
2262 "static bits_n_strings: BitsNStrings<'static> = BitsNStrings {\n"
2263 "    mybits: BITS,\n"
2264 "    mystring: STRING\n"
2265 "};\n"
2266 "~~~~\n"
2267 msgstr ""
2268
2269 #. type: Plain text
2270 #: doc/rust.md:1139
2271 msgid "#### Mutable statics"
2272 msgstr ""
2273
2274 #. type: Plain text
2275 #: doc/rust.md:1147
2276 msgid ""
2277 "If a static item is declared with the ```mut``` keyword, then it is allowed "
2278 "to be modified by the program. One of Rust's goals is to make concurrency "
2279 "bugs hard to run into, and this is obviously a very large source of race "
2280 "conditions or other bugs. For this reason, an ```unsafe``` block is required "
2281 "when either reading or writing a mutable static variable. Care should be "
2282 "taken to ensure that modifications to a mutable static are safe with respect "
2283 "to other tasks running in the same process."
2284 msgstr ""
2285
2286 #. type: Plain text
2287 #: doc/rust.md:1150
2288 msgid ""
2289 "Mutable statics are still very useful, however. They can be used with C "
2290 "libraries and can also be bound from C libraries (in an ```extern``` block)."
2291 msgstr ""
2292
2293 #. type: Plain text
2294 #: doc/rust.md:1153
2295 msgid "~~~ # fn atomic_add(_: &mut uint, _: uint) -> uint { 2 }"
2296 msgstr ""
2297
2298 #. type: Plain text
2299 #: doc/rust.md:1155
2300 msgid "static mut LEVELS: uint = 0;"
2301 msgstr ""
2302
2303 #. type: Plain text
2304 #: doc/rust.md:1163
2305 #, no-wrap
2306 msgid ""
2307 "// This violates the idea of no shared state, and this doesn't internally\n"
2308 "// protect against races, so this function is `unsafe`\n"
2309 "unsafe fn bump_levels_unsafe1() -> uint {\n"
2310 "    let ret = LEVELS;\n"
2311 "    LEVELS += 1;\n"
2312 "    return ret;\n"
2313 "}\n"
2314 msgstr ""
2315
2316 #. type: Plain text
2317 #: doc/rust.md:1170
2318 #, no-wrap
2319 msgid ""
2320 "// Assuming that we have an atomic_add function which returns the old value,\n"
2321 "// this function is \"safe\" but the meaning of the return value may not be what\n"
2322 "// callers expect, so it's still marked as `unsafe`\n"
2323 "unsafe fn bump_levels_unsafe2() -> uint {\n"
2324 "    return atomic_add(&mut LEVELS, 1);\n"
2325 "}\n"
2326 msgstr ""
2327
2328 #. type: Plain text
2329 #: doc/rust.md:1172
2330 msgid "~~~"
2331 msgstr ""
2332
2333 #. type: Plain text
2334 #: doc/rust.md:1174
2335 msgid "### Traits"
2336 msgstr ""
2337
2338 #. type: Plain text
2339 #: doc/rust.md:1176
2340 msgid "A _trait_ describes a set of method types."
2341 msgstr ""
2342
2343 #. type: Plain text
2344 #: doc/rust.md:1181
2345 msgid ""
2346 "Traits can include default implementations of methods, written in terms of "
2347 "some unknown [`self` type](#self-types); the `self` type may either be "
2348 "completely unspecified, or constrained by some other trait."
2349 msgstr ""
2350
2351 #. type: Plain text
2352 #: doc/rust.md:1183
2353 msgid ""
2354 "Traits are implemented for specific types through separate [implementations]"
2355 "(#implementations)."
2356 msgstr ""
2357
2358 #. type: Plain text
2359 #: doc/rust.md:1187
2360 msgid "~~~~ # type Surface = int; # type BoundingBox = int;"
2361 msgstr ""
2362
2363 #. type: Plain text
2364 #: doc/rust.md:1193
2365 #, no-wrap
2366 msgid ""
2367 "trait Shape {\n"
2368 "    fn draw(&self, Surface);\n"
2369 "    fn bounding_box(&self) -> BoundingBox;\n"
2370 "}\n"
2371 "~~~~\n"
2372 msgstr ""
2373
2374 #. type: Plain text
2375 #: doc/rust.md:1197
2376 msgid ""
2377 "This defines a trait with two methods.  All values that have "
2378 "[implementations](#implementations) of this trait in scope can have their "
2379 "`draw` and `bounding_box` methods called, using `value.bounding_box()` "
2380 "[syntax](#method-call-expressions)."
2381 msgstr ""
2382
2383 #. type: Plain text
2384 #: doc/rust.md:1200
2385 msgid ""
2386 "Type parameters can be specified for a trait to make it generic.  These "
2387 "appear after the trait name, using the same syntax used in [generic "
2388 "functions](#generic-functions)."
2389 msgstr ""
2390
2391 #. type: Plain text
2392 #: doc/rust.md:1208
2393 #, no-wrap
2394 msgid ""
2395 "~~~~\n"
2396 "trait Seq<T> {\n"
2397 "   fn len(&self) -> uint;\n"
2398 "   fn elt_at(&self, n: uint) -> T;\n"
2399 "   fn iter(&self, &fn(T));\n"
2400 "}\n"
2401 "~~~~\n"
2402 msgstr ""
2403
2404 #. type: Plain text
2405 #: doc/rust.md:1214
2406 msgid ""
2407 "Generic functions may use traits as _bounds_ on their type parameters.  This "
2408 "will have two effects: only types that have the trait may instantiate the "
2409 "parameter, and within the generic function, the methods of the trait can be "
2410 "called on values that have the parameter's type.  For example:"
2411 msgstr ""
2412
2413 #. type: Plain text
2414 #: doc/rust.md:1218
2415 msgid "~~~~ # type Surface = int; # trait Shape { fn draw(&self, Surface); }"
2416 msgstr ""
2417
2418 #. type: Plain text
2419 #: doc/rust.md:1224
2420 #, no-wrap
2421 msgid ""
2422 "fn draw_twice<T: Shape>(surface: Surface, sh: T) {\n"
2423 "    sh.draw(surface);\n"
2424 "    sh.draw(surface);\n"
2425 "}\n"
2426 "~~~~\n"
2427 msgstr ""
2428
2429 #. type: Plain text
2430 #: doc/rust.md:1229
2431 msgid ""
2432 "Traits also define an [object type](#object-types) with the same name as the "
2433 "trait.  Values of this type are created by [casting](#type-cast-expressions) "
2434 "pointer values (pointing to a type for which an implementation of the given "
2435 "trait is in scope)  to pointers to the trait name, used as a type."
2436 msgstr ""
2437
2438 #. type: Plain text
2439 #: doc/rust.md:1234
2440 msgid "~~~~ # trait Shape { } # impl Shape for int { } # let mycircle = 0;"
2441 msgstr ""
2442
2443 #. type: Plain text
2444 #: doc/rust.md:1237
2445 msgid "let myshape: @Shape = @mycircle as @Shape; ~~~~"
2446 msgstr ""
2447
2448 #. type: Plain text
2449 #: doc/rust.md:1243
2450 msgid ""
2451 "The resulting value is a managed box containing the value that was cast, "
2452 "along with information that identifies the methods of the implementation "
2453 "that was used.  Values with a trait type can have [methods called](#method-"
2454 "call-expressions) on them, for any method in the trait, and can be used to "
2455 "instantiate type parameters that are bounded by the trait."
2456 msgstr ""
2457
2458 #. type: Plain text
2459 #: doc/rust.md:1251
2460 msgid ""
2461 "Trait methods may be static, which means that they lack a `self` argument.  "
2462 "This means that they can only be called with function call syntax (`f(x)`)  "
2463 "and not method call syntax (`obj.f()`).  The way to refer to the name of a "
2464 "static method is to qualify it with the trait name, treating the trait name "
2465 "like a module.  For example:"
2466 msgstr ""
2467
2468 #. type: Plain text
2469 #: doc/rust.md:1261
2470 #, no-wrap
2471 msgid ""
2472 "~~~~\n"
2473 "trait Num {\n"
2474 "    fn from_int(n: int) -> Self;\n"
2475 "}\n"
2476 "impl Num for float {\n"
2477 "    fn from_int(n: int) -> float { n as float }\n"
2478 "}\n"
2479 "let x: float = Num::from_int(42);\n"
2480 "~~~~\n"
2481 msgstr ""
2482
2483 #. type: Plain text
2484 #: doc/rust.md:1263
2485 msgid "Traits may inherit from other traits. For example, in"
2486 msgstr ""
2487
2488 #. type: Plain text
2489 #: doc/rust.md:1268
2490 msgid ""
2491 "~~~~ trait Shape { fn area() -> float; } trait Circle : Shape { fn radius() -"
2492 "> float; } ~~~~"
2493 msgstr ""
2494
2495 #. type: Plain text
2496 #: doc/rust.md:1273
2497 msgid ""
2498 "the syntax `Circle : Shape` means that types that implement `Circle` must "
2499 "also have an implementation for `Shape`.  Multiple supertraits are separated "
2500 "by spaces, `trait Circle : Shape Eq { }`.  In an implementation of `Circle` "
2501 "for a given type `T`, methods can refer to `Shape` methods, since the "
2502 "typechecker checks that any type with an implementation of `Circle` also has "
2503 "an implementation of `Shape`."
2504 msgstr ""
2505
2506 #. type: Plain text
2507 #: doc/rust.md:1277 doc/tutorial.md:2176
2508 msgid ""
2509 "In type-parameterized functions, methods of the supertrait may be called on "
2510 "values of subtrait-bound type parameters.  Refering to the previous example "
2511 "of `trait Circle : Shape`:"
2512 msgstr ""
2513
2514 #. type: Plain text
2515 #: doc/rust.md:1286 doc/tutorial.md:2185
2516 #, no-wrap
2517 msgid ""
2518 "~~~\n"
2519 "# trait Shape { fn area(&self) -> float; }\n"
2520 "# trait Circle : Shape { fn radius(&self) -> float; }\n"
2521 "fn radius_times_area<T: Circle>(c: T) -> float {\n"
2522 "    // `c` is both a Circle and a Shape\n"
2523 "    c.radius() * c.area()\n"
2524 "}\n"
2525 "~~~\n"
2526 msgstr ""
2527
2528 #. type: Plain text
2529 #: doc/rust.md:1288 doc/tutorial.md:2187
2530 msgid "Likewise, supertrait methods may also be called on trait objects."
2531 msgstr ""
2532
2533 #. type: Plain text
2534 #: doc/rust.md:1295
2535 msgid ""
2536 "~~~ {.xfail-test} # trait Shape { fn area(&self) -> float; } # trait "
2537 "Circle : Shape { fn radius(&self) -> float; } # impl Shape for int { fn "
2538 "area(&self) -> float { 0.0 } } # impl Circle for int { fn radius(&self) -> "
2539 "float { 0.0 } } # let mycircle = 0;"
2540 msgstr ""
2541
2542 #. type: Plain text
2543 #: doc/rust.md:1299
2544 msgid ""
2545 "let mycircle: Circle = @mycircle as @Circle; let nonsense = mycircle."
2546 "radius() * mycircle.area(); ~~~"
2547 msgstr ""
2548
2549 #. type: Plain text
2550 #: doc/rust.md:1301
2551 msgid "### Implementations"
2552 msgstr ""
2553
2554 #. type: Plain text
2555 #: doc/rust.md:1303
2556 msgid ""
2557 "An _implementation_ is an item that implements a [trait](#traits) for a "
2558 "specific type."
2559 msgstr ""
2560
2561 #. type: Plain text
2562 #: doc/rust.md:1305
2563 msgid "Implementations are defined with the keyword `impl`."
2564 msgstr ""
2565
2566 #. type: Plain text
2567 #: doc/rust.md:1312
2568 msgid ""
2569 "~~~~ # struct Point {x: float, y: float}; # type Surface = int; # struct "
2570 "BoundingBox {x: float, y: float, width: float, height: float}; # trait Shape "
2571 "{ fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; } # fn "
2572 "do_draw_circle(s: Surface, c: Circle) { }"
2573 msgstr ""
2574
2575 #. type: Plain text
2576 #: doc/rust.md:1317
2577 #, no-wrap
2578 msgid ""
2579 "struct Circle {\n"
2580 "    radius: float,\n"
2581 "    center: Point,\n"
2582 "}\n"
2583 msgstr ""
2584
2585 #. type: Plain text
2586 #: doc/rust.md:1327
2587 #, no-wrap
2588 msgid ""
2589 "impl Shape for Circle {\n"
2590 "    fn draw(&self, s: Surface) { do_draw_circle(s, *self); }\n"
2591 "    fn bounding_box(&self) -> BoundingBox {\n"
2592 "        let r = self.radius;\n"
2593 "        BoundingBox{x: self.center.x - r, y: self.center.y - r,\n"
2594 "         width: 2.0 * r, height: 2.0 * r}\n"
2595 "    }\n"
2596 "}\n"
2597 "~~~~\n"
2598 msgstr ""
2599
2600 #. type: Plain text
2601 #: doc/rust.md:1334
2602 msgid ""
2603 "It is possible to define an implementation without referring to a trait.  "
2604 "The methods in such an implementation can only be used as direct calls on "
2605 "the values of the type that the implementation targets.  In such an "
2606 "implementation, the trait type and `for` after `impl` are omitted.  Such "
2607 "implementations are limited to nominal types (enums, structs), and the "
2608 "implementation must appear in the same module or a sub-module as the `self` "
2609 "type."
2610 msgstr ""
2611
2612 #. type: Plain text
2613 #: doc/rust.md:1338
2614 msgid ""
2615 "When a trait _is_ specified in an `impl`, all methods declared as part of "
2616 "the trait must be implemented, with matching types and type parameter counts."
2617 msgstr ""
2618
2619 #. type: Plain text
2620 #: doc/rust.md:1342
2621 msgid ""
2622 "An implementation can take type parameters, which can be different from the "
2623 "type parameters taken by the trait it implements.  Implementation parameters "
2624 "are written after the `impl` keyword."
2625 msgstr ""
2626
2627 #. type: Plain text
2628 #: doc/rust.md:1345
2629 msgid "~~~~ # trait Seq<T> { }"
2630 msgstr ""
2631
2632 #. type: Plain text
2633 #: doc/rust.md:1353
2634 #, no-wrap
2635 msgid ""
2636 "impl<T> Seq<T> for ~[T] {\n"
2637 "   ...\n"
2638 "}\n"
2639 "impl Seq<bool> for u32 {\n"
2640 "   /* Treat the integer as a sequence of bits */\n"
2641 "}\n"
2642 "~~~~\n"
2643 msgstr ""
2644
2645 #. type: Plain text
2646 #: doc/rust.md:1355
2647 msgid "### External blocks"
2648 msgstr ""
2649
2650 #. type: Plain text
2651 #: doc/rust.md:1360
2652 msgid ""
2653 "~~~ {.ebnf .gram} extern_block_item : \"extern\" '{' extern_block '} ; "
2654 "extern_block : [ foreign_fn ] * ; ~~~"
2655 msgstr ""
2656
2657 #. type: Plain text
2658 #: doc/rust.md:1364
2659 msgid ""
2660 "External blocks form the basis for Rust's foreign function interface.  "
2661 "Declarations in an external block describe symbols in external, non-Rust "
2662 "libraries."
2663 msgstr ""
2664
2665 #. type: Plain text
2666 #: doc/rust.md:1369
2667 msgid ""
2668 "Functions within external blocks are declared in the same way as other Rust "
2669 "functions, with the exception that they may not have a body and are instead "
2670 "terminated by a semicolon."
2671 msgstr ""
2672
2673 #. type: Plain text
2674 #: doc/rust.md:1373
2675 msgid "~~~ # use std::libc::{c_char, FILE}; # #[nolink]"
2676 msgstr ""
2677
2678 #. type: Plain text
2679 #: doc/rust.md:1378
2680 #, no-wrap
2681 msgid ""
2682 "extern {\n"
2683 "    fn fopen(filename: *c_char, mode: *c_char) -> *FILE;\n"
2684 "}\n"
2685 "~~~\n"
2686 msgstr ""
2687
2688 #. type: Plain text
2689 #: doc/rust.md:1383
2690 msgid ""
2691 "Functions within external blocks may be called by Rust code, just like "
2692 "functions defined in Rust.  The Rust compiler automatically translates "
2693 "between the Rust ABI and the foreign ABI."
2694 msgstr ""
2695
2696 #. type: Plain text
2697 #: doc/rust.md:1386
2698 msgid ""
2699 "A number of [attributes](#attributes) control the behavior of external "
2700 "blocks."
2701 msgstr ""
2702
2703 #. type: Plain text
2704 #: doc/rust.md:1390
2705 msgid ""
2706 "By default external blocks assume that the library they are calling uses the "
2707 "standard C \"cdecl\" ABI.  Other ABIs may be specified using the `abi` "
2708 "attribute as in"
2709 msgstr ""
2710
2711 #. type: Plain text
2712 #: doc/rust.md:1396
2713 msgid ""
2714 "~~~{.xfail-test} // Interface to the Windows API #[abi = \"stdcall\"] extern "
2715 "{ } ~~~"
2716 msgstr ""
2717
2718 #. type: Plain text
2719 #: doc/rust.md:1398
2720 msgid ""
2721 "The `link_name` attribute allows the name of the library to be specified."
2722 msgstr ""
2723
2724 #. type: Plain text
2725 #: doc/rust.md:1403
2726 msgid "~~~{.xfail-test} #[link_name = \"crypto\"] extern { } ~~~"
2727 msgstr ""
2728
2729 #. type: Plain text
2730 #: doc/rust.md:1409
2731 msgid ""
2732 "The `nolink` attribute tells the Rust compiler not to do any linking for the "
2733 "external block.  This is particularly useful for creating external blocks "
2734 "for libc, which tends to not follow standard library naming conventions and "
2735 "is linked to all Rust programs anyway."
2736 msgstr ""
2737
2738 #. type: Plain text
2739 #: doc/rust.md:1411
2740 msgid "## Attributes"
2741 msgstr ""
2742
2743 #. type: Plain text
2744 #: doc/rust.md:1418
2745 #, no-wrap
2746 msgid ""
2747 "~~~~~~~~{.ebnf .gram}\n"
2748 "attribute : '#' '[' attr_list ']' ;\n"
2749 "attr_list : attr [ ',' attr_list ]*\n"
2750 "attr : ident [ '=' literal\n"
2751 "             | '(' attr_list ')' ] ? ;\n"
2752 "~~~~~~~~\n"
2753 msgstr ""
2754
2755 #. type: Plain text
2756 #: doc/rust.md:1424
2757 msgid ""
2758 "Static entities in Rust -- crates, modules and items -- may have "
2759 "_attributes_ applied to them. ^[Attributes in Rust are modeled on Attributes "
2760 "in ECMA-335, C#] An attribute is a general, free-form metadatum that is "
2761 "interpreted according to name, convention, and language and compiler "
2762 "version.  Attributes may appear as any of"
2763 msgstr ""
2764
2765 #. type: Bullet: '* '
2766 #: doc/rust.md:1428
2767 msgid "A single identifier, the attribute name"
2768 msgstr ""
2769
2770 #. type: Bullet: '* '
2771 #: doc/rust.md:1428
2772 msgid ""
2773 "An identifier followed by the equals sign '=' and a literal, providing a key/"
2774 "value pair"
2775 msgstr ""
2776
2777 #. type: Bullet: '* '
2778 #: doc/rust.md:1428
2779 msgid ""
2780 "An identifier followed by a parenthesized list of sub-attribute arguments"
2781 msgstr ""
2782
2783 #. type: Plain text
2784 #: doc/rust.md:1431
2785 msgid ""
2786 "Attributes terminated by a semi-colon apply to the entity that the attribute "
2787 "is declared within. Attributes that are not terminated by a semi-colon apply "
2788 "to the next entity."
2789 msgstr ""
2790
2791 #. type: Plain text
2792 #: doc/rust.md:1433
2793 msgid "An example of attributes:"
2794 msgstr ""
2795
2796 #. type: Plain text
2797 #: doc/rust.md:1437
2798 msgid ""
2799 "~~~~~~~~{.xfail-test} // General metadata applied to the enclosing module or "
2800 "crate.  #[license = \"BSD\"];"
2801 msgstr ""
2802
2803 #. type: Plain text
2804 #: doc/rust.md:1443
2805 #, no-wrap
2806 msgid ""
2807 "// A function marked as a unit test\n"
2808 "#[test]\n"
2809 "fn test_foo() {\n"
2810 "  ...\n"
2811 "}\n"
2812 msgstr ""
2813
2814 #. type: Plain text
2815 #: doc/rust.md:1449
2816 #, no-wrap
2817 msgid ""
2818 "// A conditionally-compiled module\n"
2819 "#[cfg(target_os=\"linux\")]\n"
2820 "mod bar {\n"
2821 "  ...\n"
2822 "}\n"
2823 msgstr ""
2824
2825 #. type: Plain text
2826 #: doc/rust.md:1454
2827 msgid ""
2828 "// A lint attribute used to suppress a warning/error "
2829 "#[allow(non_camel_case_types)] pub type int8_t = i8; ~~~~~~~~"
2830 msgstr ""
2831
2832 #. type: Plain text
2833 #: doc/rust.md:1457
2834 msgid ""
2835 "> **Note:** In future versions of Rust, user-provided extensions to the "
2836 "compiler will be able to interpret attributes.  > When this facility is "
2837 "provided, the compiler will distinguish between language-reserved and user-"
2838 "available attributes."
2839 msgstr ""
2840
2841 #. type: Plain text
2842 #: doc/rust.md:1460
2843 msgid ""
2844 "At present, only the Rust compiler interprets attributes, so all attribute "
2845 "names are effectively reserved. Some significant attributes include:"
2846 msgstr ""
2847
2848 #. type: Bullet: '* '
2849 #: doc/rust.md:1471
2850 msgid "The `doc` attribute, for documenting code in-place."
2851 msgstr ""
2852
2853 #. type: Bullet: '* '
2854 #: doc/rust.md:1471
2855 msgid ""
2856 "The `cfg` attribute, for conditional-compilation by build-configuration."
2857 msgstr ""
2858
2859 #. type: Bullet: '* '
2860 #: doc/rust.md:1471
2861 msgid ""
2862 "The `lang` attribute, for custom definitions of traits and functions that "
2863 "are known to the Rust compiler (see [Language items](#language-items))."
2864 msgstr ""
2865
2866 #. type: Bullet: '* '
2867 #: doc/rust.md:1471
2868 msgid "The `link` attribute, for describing linkage metadata for a crate."
2869 msgstr ""
2870
2871 #. type: Bullet: '* '
2872 #: doc/rust.md:1471
2873 msgid "The `test` attribute, for marking functions as unit tests."
2874 msgstr ""
2875
2876 #. type: Bullet: '* '
2877 #: doc/rust.md:1471
2878 msgid ""
2879 "The `allow`, `warn`, `forbid`, and `deny` attributes, for controlling lint "
2880 "checks (see [Lint check attributes](#lint-check-attributes))."
2881 msgstr ""
2882
2883 #. type: Bullet: '* '
2884 #: doc/rust.md:1471
2885 msgid ""
2886 "The `deriving` attribute, for automatically generating implementations of "
2887 "certain traits."
2888 msgstr ""
2889
2890 #. type: Bullet: '* '
2891 #: doc/rust.md:1471
2892 msgid ""
2893 "The `static_assert` attribute, for asserting that a static bool is true at "
2894 "compiletime"
2895 msgstr ""
2896
2897 #. type: Plain text
2898 #: doc/rust.md:1473
2899 msgid ""
2900 "Other attributes may be added or removed during development of the language."
2901 msgstr ""
2902
2903 #. type: Plain text
2904 #: doc/rust.md:1475
2905 msgid "### Lint check attributes"
2906 msgstr ""
2907
2908 #. type: Plain text
2909 #: doc/rust.md:1479
2910 msgid ""
2911 "A lint check names a potentially undesirable coding pattern, such as "
2912 "unreachable code or omitted documentation, for the static entity to which "
2913 "the attribute applies."
2914 msgstr ""
2915
2916 #. type: Plain text
2917 #: doc/rust.md:1481
2918 msgid "For any lint check `C`:"
2919 msgstr ""
2920
2921 #. type: Bullet: ' * '
2922 #: doc/rust.md:1488
2923 msgid "`warn(C)` warns about violations of `C` but continues compilation,"
2924 msgstr ""
2925
2926 #. type: Bullet: ' * '
2927 #: doc/rust.md:1488
2928 msgid "`deny(C)` signals an error after encountering a violation of `C`,"
2929 msgstr ""
2930
2931 #. type: Plain text
2932 #: doc/rust.md:1488
2933 #, no-wrap
2934 msgid ""
2935 " * `allow(C)` overrides the check for `C` so that violations will go\n"
2936 "    unreported,\n"
2937 " * `forbid(C)` is the same as `deny(C)`, but also forbids uses of\n"
2938 "   `allow(C)` within the entity.\n"
2939 msgstr ""
2940
2941 #. type: Plain text
2942 #: doc/rust.md:1491
2943 msgid ""
2944 "The lint checks supported by the compiler can be found via `rustc -W help`, "
2945 "along with their default settings."
2946 msgstr ""
2947
2948 #. type: Plain text
2949 #: doc/rust.md:1497
2950 #, no-wrap
2951 msgid ""
2952 "~~~{.xfail-test}\n"
2953 "mod m1 {\n"
2954 "    // Missing documentation is ignored here\n"
2955 "    #[allow(missing_doc)]\n"
2956 "    pub fn undocumented_one() -> int { 1 }\n"
2957 msgstr ""
2958
2959 #. type: Plain text
2960 #: doc/rust.md:1501
2961 #, no-wrap
2962 msgid ""
2963 "    // Missing documentation signals a warning here\n"
2964 "    #[warn(missing_doc)]\n"
2965 "    pub fn undocumented_too() -> int { 2 }\n"
2966 msgstr ""
2967
2968 #. type: Plain text
2969 #: doc/rust.md:1507
2970 #, no-wrap
2971 msgid ""
2972 "    // Missing documentation signals an error here\n"
2973 "    #[deny(missing_doc)]\n"
2974 "    pub fn undocumented_end() -> int { 3 }\n"
2975 "}\n"
2976 "~~~\n"
2977 msgstr ""
2978
2979 #. type: Plain text
2980 #: doc/rust.md:1510
2981 msgid ""
2982 "This example shows how one can use `allow` and `warn` to toggle a particular "
2983 "check on and off."
2984 msgstr ""
2985
2986 #. type: Plain text
2987 #: doc/rust.md:1518
2988 #, no-wrap
2989 msgid ""
2990 "~~~{.xfail-test}\n"
2991 "#[warn(missing_doc)]\n"
2992 "mod m2{\n"
2993 "    #[allow(missing_doc)]\n"
2994 "    mod nested {\n"
2995 "        // Missing documentation is ignored here\n"
2996 "        pub fn undocumented_one() -> int { 1 }\n"
2997 msgstr ""
2998
2999 #. type: Plain text
3000 #: doc/rust.md:1524
3001 #, no-wrap
3002 msgid ""
3003 "        // Missing documentation signals a warning here,\n"
3004 "        // despite the allow above.\n"
3005 "        #[warn(missing_doc)]\n"
3006 "        pub fn undocumented_two() -> int { 2 }\n"
3007 "    }\n"
3008 msgstr ""
3009
3010 #. type: Plain text
3011 #: doc/rust.md:1529
3012 #, no-wrap
3013 msgid ""
3014 "    // Missing documentation signals a warning here\n"
3015 "    pub fn undocumented_too() -> int { 3 }\n"
3016 "}\n"
3017 "~~~\n"
3018 msgstr ""
3019
3020 #. type: Plain text
3021 #: doc/rust.md:1532
3022 msgid ""
3023 "This example shows how one can use `forbid` to disallow uses of `allow` for "
3024 "that lint check."
3025 msgstr ""
3026
3027 #. type: Plain text
3028 #: doc/rust.md:1542
3029 #, no-wrap
3030 msgid ""
3031 "~~~{.xfail-test}\n"
3032 "#[forbid(missing_doc)]\n"
3033 "mod m3 {\n"
3034 "    // Attempting to toggle warning signals an error here\n"
3035 "    #[allow(missing_doc)]\n"
3036 "    /// Returns 2.\n"
3037 "    pub fn undocumented_too() -> int { 2 }\n"
3038 "}\n"
3039 "~~~\n"
3040 msgstr ""
3041
3042 #. type: Plain text
3043 #: doc/rust.md:1544
3044 msgid "### Language items"
3045 msgstr ""
3046
3047 #. type: Plain text
3048 #: doc/rust.md:1550
3049 msgid ""
3050 "Some primitive Rust operations are defined in Rust code, rather than being "
3051 "implemented directly in C or assembly language.  The definitions of these "
3052 "operations have to be easy for the compiler to find.  The `lang` attribute "
3053 "makes it possible to declare these operations.  For example, the `str` "
3054 "module in the Rust standard library defines the string equality function:"
3055 msgstr ""
3056
3057 #. type: Plain text
3058 #: doc/rust.md:1557
3059 #, no-wrap
3060 msgid ""
3061 "~~~ {.xfail-test}\n"
3062 "#[lang=\"str_eq\"]\n"
3063 "pub fn eq_slice(a: &str, b: &str) -> bool {\n"
3064 "    // details elided\n"
3065 "}\n"
3066 "~~~\n"
3067 msgstr ""
3068
3069 #. type: Plain text
3070 #: doc/rust.md:1561
3071 msgid ""
3072 "The name `str_eq` has a special meaning to the Rust compiler, and the "
3073 "presence of this definition means that it will use this definition when "
3074 "generating calls to the string equality function."
3075 msgstr ""
3076
3077 #. type: Plain text
3078 #: doc/rust.md:1563
3079 msgid "A complete list of the built-in language items follows:"
3080 msgstr ""
3081
3082 #. type: Plain text
3083 #: doc/rust.md:1565
3084 msgid "#### Traits"
3085 msgstr ""
3086
3087 #. type: Plain text
3088 #: doc/rust.md:1604
3089 #, no-wrap
3090 msgid ""
3091 "`const`\n"
3092 "  : Cannot be mutated.\n"
3093 "`owned`\n"
3094 "  : Are uniquely owned.\n"
3095 "`durable`\n"
3096 "  : Contain borrowed pointers.\n"
3097 "`drop`\n"
3098 "  : Have finalizers.\n"
3099 "`add`\n"
3100 "  : Elements can be added (for example, integers and floats).\n"
3101 "`sub`\n"
3102 "  : Elements can be subtracted.\n"
3103 "`mul`\n"
3104 "  : Elements can be multiplied.\n"
3105 "`div`\n"
3106 "  : Elements have a division operation.\n"
3107 "`rem`\n"
3108 "  : Elements have a remainder operation.\n"
3109 "`neg`\n"
3110 "  : Elements can be negated arithmetically.\n"
3111 "`not`\n"
3112 "  : Elements can be negated logically.\n"
3113 "`bitxor`\n"
3114 "  : Elements have an exclusive-or operation.\n"
3115 "`bitand`\n"
3116 "  : Elements have a bitwise `and` operation.\n"
3117 "`bitor`\n"
3118 "  : Elements have a bitwise `or` operation.\n"
3119 "`shl`\n"
3120 "  : Elements have a left shift operation.\n"
3121 "`shr`\n"
3122 "  : Elements have a right shift operation.\n"
3123 "`index`\n"
3124 "  : Elements can be indexed.\n"
3125 "`eq`\n"
3126 "  : Elements can be compared for equality.\n"
3127 "`ord`\n"
3128 "  : Elements have a partial ordering.\n"
3129 msgstr ""
3130
3131 #. type: Plain text
3132 #: doc/rust.md:1606
3133 msgid "#### Operations"
3134 msgstr ""
3135
3136 #. type: Plain text
3137 #: doc/rust.md:1636
3138 #, no-wrap
3139 msgid ""
3140 "`str_eq`\n"
3141 "  : Compare two strings for equality.\n"
3142 "`uniq_str_eq`\n"
3143 "  : Compare two owned strings for equality.\n"
3144 "`annihilate`\n"
3145 "  : Destroy a box before freeing it.\n"
3146 "`log_type`\n"
3147 "  : Generically print a string representation of any type.\n"
3148 "`fail_`\n"
3149 "  : Abort the program with an error.\n"
3150 "`fail_bounds_check`\n"
3151 "  : Abort the program with a bounds check error.\n"
3152 "`exchange_malloc`\n"
3153 "  : Allocate memory on the exchange heap.\n"
3154 "`exchange_free`\n"
3155 "  : Free memory that was allocated on the exchange heap.\n"
3156 "`malloc`\n"
3157 "  : Allocate memory on the managed heap.\n"
3158 "`free`\n"
3159 "  : Free memory that was allocated on the managed heap.\n"
3160 "`borrow_as_imm`\n"
3161 "  : Create an immutable borrowed pointer to a mutable value.\n"
3162 "`return_to_mut`\n"
3163 "  : Release a borrowed pointer created with `return_to_mut`\n"
3164 "`check_not_borrowed`\n"
3165 "  : Fail if a value has existing borrowed pointers to it.\n"
3166 "`strdup_uniq`\n"
3167 "  : Return a new unique string\n"
3168 "    containing a copy of the contents of a unique string.\n"
3169 msgstr ""
3170
3171 #. type: Plain text
3172 #: doc/rust.md:1639
3173 msgid ""
3174 "> **Note:** This list is likely to become out of date. We should auto-"
3175 "generate it > from `librustc/middle/lang_items.rs`."
3176 msgstr ""
3177
3178 #. type: Plain text
3179 #: doc/rust.md:1641
3180 msgid "### Deriving"
3181 msgstr ""
3182
3183 #. type: Plain text
3184 #: doc/rust.md:1647
3185 msgid ""
3186 "The `deriving` attribute allows certain traits to be automatically "
3187 "implemented for data structures. For example, the following will create an "
3188 "`impl` for the `Eq` and `Clone` traits for `Foo`, the type parameter `T` "
3189 "will be given the `Eq` or `Clone` constraints for the appropriate `impl`:"
3190 msgstr ""
3191
3192 #. type: Plain text
3193 #: doc/rust.md:1655
3194 #, no-wrap
3195 msgid ""
3196 "~~~\n"
3197 "#[deriving(Eq, Clone)]\n"
3198 "struct Foo<T> {\n"
3199 "    a: int,\n"
3200 "    b: T\n"
3201 "}\n"
3202 "~~~\n"
3203 msgstr ""
3204
3205 #. type: Plain text
3206 #: doc/rust.md:1657
3207 msgid "The generated `impl` for `Eq` is equivalent to"
3208 msgstr ""
3209
3210 #. type: Plain text
3211 #: doc/rust.md:1664
3212 #, no-wrap
3213 msgid ""
3214 "~~~\n"
3215 "# struct Foo<T> { a: int, b: T }\n"
3216 "impl<T: Eq> Eq for Foo<T> {\n"
3217 "    fn eq(&self, other: &Foo<T>) -> bool {\n"
3218 "        self.a == other.a && self.b == other.b\n"
3219 "    }\n"
3220 msgstr ""
3221
3222 #. type: Plain text
3223 #: doc/rust.md:1670
3224 #, no-wrap
3225 msgid ""
3226 "    fn ne(&self, other: &Foo<T>) -> bool {\n"
3227 "        self.a != other.a || self.b != other.b\n"
3228 "    }\n"
3229 "}\n"
3230 "~~~\n"
3231 msgstr ""
3232
3233 #. type: Plain text
3234 #: doc/rust.md:1672
3235 msgid "Supported traits for `deriving` are:"
3236 msgstr ""
3237
3238 #. type: Bullet: '* '
3239 #: doc/rust.md:1683
3240 msgid "Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`."
3241 msgstr ""
3242
3243 #. type: Bullet: '* '
3244 #: doc/rust.md:1683
3245 msgid "Serialization: `Encodable`, `Decodable`. These require `extra`."
3246 msgstr ""
3247
3248 #. type: Bullet: '* '
3249 #: doc/rust.md:1683
3250 msgid "`Clone` and `DeepClone`, to perform (deep) copies."
3251 msgstr ""
3252
3253 #. type: Bullet: '* '
3254 #: doc/rust.md:1683
3255 msgid "`IterBytes`, to iterate over the bytes in a data type."
3256 msgstr ""
3257
3258 #. type: Bullet: '* '
3259 #: doc/rust.md:1683
3260 msgid "`Rand`, to create a random instance of a data type."
3261 msgstr ""
3262
3263 #. type: Bullet: '* '
3264 #: doc/rust.md:1683
3265 msgid "`Zero`, to create an zero (or empty) instance of a data type."
3266 msgstr ""
3267
3268 #. type: Bullet: '* '
3269 #: doc/rust.md:1683
3270 msgid ""
3271 "`ToStr`, to convert to a string. For a type with this instance, `obj."
3272 "to_str()` has similar output as `fmt!(\"%?\", obj)`, but it differs in that "
3273 "each constituent field of the type must also implement `ToStr` and will have "
3274 "`field.to_str()` invoked to build up the result."
3275 msgstr ""
3276
3277 #. type: Plain text
3278 #: doc/rust.md:1685
3279 msgid "# Statements and expressions"
3280 msgstr ""
3281
3282 #. type: Plain text
3283 #: doc/rust.md:1692
3284 msgid ""
3285 "Rust is _primarily_ an expression language. This means that most forms of "
3286 "value-producing or effect-causing evaluation are directed by the uniform "
3287 "syntax category of _expressions_. Each kind of expression can typically "
3288 "_nest_ within each other kind of expression, and rules for evaluation of "
3289 "expressions involve specifying both the value produced by the expression and "
3290 "the order in which its sub-expressions are themselves evaluated."
3291 msgstr ""
3292
3293 #. type: Plain text
3294 #: doc/rust.md:1695
3295 msgid ""
3296 "In contrast, statements in Rust serve _mostly_ to contain and explicitly "
3297 "sequence expression evaluation."
3298 msgstr ""
3299
3300 #. type: Plain text
3301 #: doc/rust.md:1697
3302 msgid "## Statements"
3303 msgstr ""
3304
3305 #. type: Plain text
3306 #: doc/rust.md:1700
3307 msgid ""
3308 "A _statement_ is a component of a block, which is in turn a component of an "
3309 "outer [expression](#expressions) or [function](#functions)."
3310 msgstr ""
3311
3312 #. type: Plain text
3313 #: doc/rust.md:1704
3314 msgid ""
3315 "Rust has two kinds of statement: [declaration statements](#declaration-"
3316 "statements) and [expression statements](#expression-statements)."
3317 msgstr ""
3318
3319 #. type: Plain text
3320 #: doc/rust.md:1706
3321 msgid "### Declaration statements"
3322 msgstr ""
3323
3324 #. type: Plain text
3325 #: doc/rust.md:1709
3326 msgid ""
3327 "A _declaration statement_ is one that introduces one or more *names* into "
3328 "the enclosing statement block.  The declared names may denote new slots or "
3329 "new items."
3330 msgstr ""
3331
3332 #. type: Plain text
3333 #: doc/rust.md:1711
3334 msgid "#### Item declarations"
3335 msgstr ""
3336
3337 #. type: Plain text
3338 #: doc/rust.md:1718
3339 msgid ""
3340 "An _item declaration statement_ has a syntactic form identical to an [item]"
3341 "(#items) declaration within a module. Declaring an item -- a function, "
3342 "enumeration, structure, type, static, trait, implementation or module -- "
3343 "locally within a statement block is simply a way of restricting its scope to "
3344 "a narrow region containing all of its uses; it is otherwise identical in "
3345 "meaning to declaring the item outside the statement block."
3346 msgstr ""
3347
3348 #. type: Plain text
3349 #: doc/rust.md:1721
3350 msgid ""
3351 "Note: there is no implicit capture of the function's dynamic environment "
3352 "when declaring a function-local item."
3353 msgstr ""
3354
3355 #. type: Plain text
3356 #: doc/rust.md:1724
3357 msgid "#### Slot declarations"
3358 msgstr ""
3359
3360 #. type: Plain text
3361 #: doc/rust.md:1729
3362 msgid ""
3363 "~~~~~~~~{.ebnf .gram} let_decl : \"let\" pat [':' type ] ? [ init ] ? ';' ; "
3364 "init : [ '=' ] expr ; ~~~~~~~~"
3365 msgstr ""
3366
3367 #. type: Plain text
3368 #: doc/rust.md:1735
3369 msgid ""
3370 "A _slot declaration_ introduces a new set of slots, given by a pattern.  The "
3371 "pattern may be followed by a type annotation, and/or an initializer "
3372 "expression.  When no type annotation is given, the compiler will infer the "
3373 "type, or signal an error if insufficient type information is available for "
3374 "definite inference.  Any slots introduced by a slot declaration are visible "
3375 "from the point of declaration until the end of the enclosing block scope."
3376 msgstr ""
3377
3378 #. type: Plain text
3379 #: doc/rust.md:1737
3380 msgid "### Expression statements"
3381 msgstr ""
3382
3383 #. type: Plain text
3384 #: doc/rust.md:1742
3385 msgid ""
3386 "An _expression statement_ is one that evaluates an [expression]"
3387 "(#expressions)  and ignores its result.  The type of an expression statement "
3388 "`e;` is always `()`, regardless of the type of `e`.  As a rule, an "
3389 "expression statement's purpose is to trigger the effects of evaluating its "
3390 "expression."
3391 msgstr ""
3392
3393 #. type: Plain text
3394 #: doc/rust.md:1744
3395 msgid "## Expressions"
3396 msgstr ""
3397
3398 #. type: Plain text
3399 #: doc/rust.md:1753
3400 #, no-wrap
3401 msgid ""
3402 "An expression may have two roles: it always produces a *value*, and it may have *effects*\n"
3403 "(otherwise known as \"side effects\").\n"
3404 "An expression *evaluates to* a value, and has effects during *evaluation*.\n"
3405 "Many expressions contain sub-expressions (operands).\n"
3406 "The meaning of each kind of expression dictates several things:\n"
3407 "  * Whether or not to evaluate the sub-expressions when evaluating the expression\n"
3408 "  * The order in which to evaluate the sub-expressions\n"
3409 "  * How to combine the sub-expressions' values to obtain the value of the expression.\n"
3410 msgstr ""
3411
3412 #. type: Plain text
3413 #: doc/rust.md:1758
3414 msgid ""
3415 "In this way, the structure of expressions dictates the structure of "
3416 "execution.  Blocks are just another kind of expression, so blocks, "
3417 "statements, expressions, and blocks again can recursively nest inside each "
3418 "other to an arbitrary depth."
3419 msgstr ""
3420
3421 #. type: Plain text
3422 #: doc/rust.md:1760
3423 msgid "#### Lvalues, rvalues and temporaries"
3424 msgstr ""
3425
3426 #. type: Plain text
3427 #: doc/rust.md:1764
3428 msgid ""
3429 "Expressions are divided into two main categories: _lvalues_ and _rvalues_.  "
3430 "Likewise within each expression, sub-expressions may occur in _lvalue "
3431 "context_ or _rvalue context_.  The evaluation of an expression depends both "
3432 "on its own category and the context it occurs within."
3433 msgstr ""
3434
3435 #. type: Plain text
3436 #: doc/rust.md:1767
3437 msgid ""
3438 "[Path](#path-expressions), [field](#field-expressions) and [index](#index-"
3439 "expressions) expressions are lvalues.  All other expressions are rvalues."
3440 msgstr ""
3441
3442 #. type: Plain text
3443 #: doc/rust.md:1775
3444 msgid ""
3445 "The left operand of an [assignment](#assignment-expressions), [binary move]"
3446 "(#binary-move-expressions) or [compound-assignment](#compound-assignment-"
3447 "expressions) expression is an lvalue context, as is the single operand of a "
3448 "unary [borrow](#unary-operator-expressions), or [move](#unary-move-"
3449 "expressions) expression, and _both_ operands of a [swap](#swap-expressions) "
3450 "expression.  All other expression contexts are rvalue contexts."
3451 msgstr ""
3452
3453 #. type: Plain text
3454 #: doc/rust.md:1778
3455 msgid ""
3456 "When an lvalue is evaluated in an _lvalue context_, it denotes a memory "
3457 "location; when evaluated in an _rvalue context_, it denotes the value held "
3458 "_in_ that memory location."
3459 msgstr ""
3460
3461 #. type: Plain text
3462 #: doc/rust.md:1781
3463 msgid ""
3464 "When an rvalue is used in lvalue context, a temporary un-named lvalue is "
3465 "created and used instead.  A temporary's lifetime equals the largest "
3466 "lifetime of any borrowed pointer that points to it."
3467 msgstr ""
3468
3469 #. type: Plain text
3470 #: doc/rust.md:1783
3471 msgid "#### Moved and copied types"
3472 msgstr ""
3473
3474 #. type: Plain text
3475 #: doc/rust.md:1792
3476 msgid ""
3477 "When a [local variable](#memory-slots) is used as an [rvalue](#lvalues-"
3478 "rvalues-and-temporaries)  the variable will either be [moved](#move-"
3479 "expressions) or copied, depending on its type.  For types that contain "
3480 "[owning pointers](#owning-pointers)  or values that implement the special "
3481 "trait `Drop`, the variable is moved.  All other types are copied."
3482 msgstr ""
3483
3484 #. type: Plain text
3485 #: doc/rust.md:1795
3486 msgid "### Literal expressions"
3487 msgstr ""
3488
3489 #. type: Plain text
3490 #: doc/rust.md:1799
3491 msgid ""
3492 "A _literal expression_ consists of one of the [literal](#literals)  forms "
3493 "described earlier. It directly describes a number, character, string, "
3494 "boolean value, or the unit value."
3495 msgstr ""
3496
3497 #. type: Plain text
3498 #: doc/rust.md:1806
3499 #, no-wrap
3500 msgid ""
3501 "~~~~~~~~ {.literals}\n"
3502 "();        // unit type\n"
3503 "\"hello\";   // string type\n"
3504 "'5';       // character type\n"
3505 "5;         // integer type\n"
3506 "~~~~~~~~\n"
3507 msgstr ""
3508
3509 #. type: Plain text
3510 #: doc/rust.md:1808
3511 msgid "### Path expressions"
3512 msgstr ""
3513
3514 #. type: Plain text
3515 #: doc/rust.md:1811
3516 msgid ""
3517 "A [path](#paths) used as an expression context denotes either a local "
3518 "variable or an item.  Path expressions are [lvalues](#lvalues-rvalues-and-"
3519 "temporaries)."
3520 msgstr ""
3521
3522 #. type: Plain text
3523 #: doc/rust.md:1813
3524 msgid "### Tuple expressions"
3525 msgstr ""
3526
3527 #. type: Plain text
3528 #: doc/rust.md:1817
3529 msgid ""
3530 "Tuples are written by enclosing one or more comma-separated expressions in "
3531 "parentheses. They are used to create [tuple-typed](#tuple-types)  values."
3532 msgstr ""
3533
3534 #. type: Plain text
3535 #: doc/rust.md:1823
3536 msgid "~~~~~~~~ {.tuple} (0,); (0f, 4.5f); (\"a\", 4u, true); ~~~~~~~~"
3537 msgstr ""
3538
3539 #. type: Plain text
3540 #: doc/rust.md:1825
3541 msgid "### Structure expressions"
3542 msgstr ""
3543
3544 #. type: Plain text
3545 #: doc/rust.md:1834
3546 #, no-wrap
3547 msgid ""
3548 "~~~~~~~~{.ebnf .gram}\n"
3549 "struct_expr : expr_path '{' ident ':' expr\n"
3550 "                      [ ',' ident ':' expr ] *\n"
3551 "                      [ \"..\" expr ] '}' |\n"
3552 "              expr_path '(' expr\n"
3553 "                      [ ',' expr ] * ')' |\n"
3554 "              expr_path\n"
3555 "~~~~~~~~\n"
3556 msgstr ""
3557
3558 #. type: Plain text
3559 #: doc/rust.md:1841
3560 msgid ""
3561 "There are several forms of structure expressions.  A _structure expression_ "
3562 "consists of the [path](#paths) of a [structure item](#structures), followed "
3563 "by a brace-enclosed list of one or more comma-separated name-value pairs, "
3564 "providing the field values of a new instance of the structure.  A field name "
3565 "can be any identifier, and is separated from its value expression by a "
3566 "colon.  The location denoted by a structure field is mutable if and only if "
3567 "the enclosing structure is mutable."
3568 msgstr ""
3569
3570 #. type: Plain text
3571 #: doc/rust.md:1846
3572 msgid ""
3573 "A _tuple structure expression_ consists of the [path](#paths) of a "
3574 "[structure item](#structures), followed by a parenthesized list of one or "
3575 "more comma-separated expressions (in other words, the path of a structure "
3576 "item followed by a tuple expression).  The structure item must be a tuple "
3577 "structure item."
3578 msgstr ""
3579
3580 #. type: Plain text
3581 #: doc/rust.md:1848
3582 msgid ""
3583 "A _unit-like structure expression_ consists only of the [path](#paths) of a "
3584 "[structure item](#structures)."
3585 msgstr ""
3586
3587 #. type: Plain text
3588 #: doc/rust.md:1850
3589 msgid "The following are examples of structure expressions:"
3590 msgstr ""
3591
3592 #. type: Plain text
3593 #: doc/rust.md:1861
3594 msgid ""
3595 "~~~~ # struct Point { x: float, y: float } # struct TuplePoint(float, "
3596 "float); # mod game { pub struct User<'self> { name: &'self str, age: uint, "
3597 "score: uint } } # struct Cookie; fn some_fn<T>(t: T) {} Point {x: 10f, y: "
3598 "20f}; TuplePoint(10f, 20f); let u = game::User {name: \"Joe\", age: 35, "
3599 "score: 100_000}; some_fn::<Cookie>(Cookie); ~~~~"
3600 msgstr ""
3601
3602 #. type: Plain text
3603 #: doc/rust.md:1864
3604 msgid ""
3605 "A structure expression forms a new value of the named structure type.  Note "
3606 "that for a given *unit-like* structure type, this will always be the same "
3607 "value."
3608 msgstr ""
3609
3610 #. type: Plain text
3611 #: doc/rust.md:1871
3612 msgid ""
3613 "A structure expression can terminate with the syntax `..` followed by an "
3614 "expression to denote a functional update.  The expression following `..` "
3615 "(the base) must have the same structure type as the new structure type being "
3616 "formed.  The entire expression denotes the result of allocating a new "
3617 "structure (with the same type as the base expression)  with the given values "
3618 "for the fields that were explicitly specified and the values in the base "
3619 "record for all other fields."
3620 msgstr ""
3621
3622 #. type: Plain text
3623 #: doc/rust.md:1877
3624 msgid ""
3625 "~~~~ # struct Point3d { x: int, y: int, z: int } let base = Point3d {x: 1, "
3626 "y: 2, z: 3}; Point3d {y: 0, z: 10, .. base}; ~~~~"
3627 msgstr ""
3628
3629 #. type: Plain text
3630 #: doc/rust.md:1879
3631 msgid "### Record expressions"
3632 msgstr ""
3633
3634 #. type: Plain text
3635 #: doc/rust.md:1885
3636 #, no-wrap
3637 msgid ""
3638 "~~~~~~~~{.ebnf .gram}\n"
3639 "rec_expr : '{' ident ':' expr\n"
3640 "               [ ',' ident ':' expr ] *\n"
3641 "               [ \"..\" expr ] '}'\n"
3642 "~~~~~~~~\n"
3643 msgstr ""
3644
3645 #. type: Plain text
3646 #: doc/rust.md:1887
3647 msgid "### Method-call expressions"
3648 msgstr ""
3649
3650 #. type: Plain text
3651 #: doc/rust.md:1891
3652 msgid ""
3653 "~~~~~~~~{.ebnf .gram} method_call_expr : expr '.' ident paren_expr_list ; "
3654 "~~~~~~~~"
3655 msgstr ""
3656
3657 #. type: Plain text
3658 #: doc/rust.md:1896
3659 msgid ""
3660 "A _method call_ consists of an expression followed by a single dot, an "
3661 "identifier, and a parenthesized expression-list.  Method calls are resolved "
3662 "to methods on specific traits, either statically dispatching to a method if "
3663 "the exact `self`-type of the left-hand-side is known, or dynamically "
3664 "dispatching if the left-hand-side expression is an indirect [object type]"
3665 "(#object-types)."
3666 msgstr ""
3667
3668 #. type: Plain text
3669 #: doc/rust.md:1899
3670 msgid "### Field expressions"
3671 msgstr ""
3672
3673 #. type: Plain text
3674 #: doc/rust.md:1903
3675 msgid "~~~~~~~~{.ebnf .gram} field_expr : expr '.' ident ~~~~~~~~"
3676 msgstr ""
3677
3678 #. type: Plain text
3679 #: doc/rust.md:1907
3680 msgid ""
3681 "A _field expression_ consists of an expression followed by a single dot and "
3682 "an identifier, when not immediately followed by a parenthesized expression-"
3683 "list (the latter is a [method call expression](#method-call-expressions)).  "
3684 "A field expression denotes a field of a [structure](#structure-types)."
3685 msgstr ""
3686
3687 #. type: Plain text
3688 #: doc/rust.md:1912
3689 msgid "~~~~~~~~ {.field} myrecord.myfield; {a: 10, b: 20}.a; ~~~~~~~~"
3690 msgstr ""
3691
3692 #. type: Plain text
3693 #: doc/rust.md:1915
3694 msgid ""
3695 "A field access on a record is an [lvalue](#lvalues-rvalues-and-temporaries) "
3696 "referring to the value of that field.  When the field is mutable, it can be "
3697 "[assigned](#assignment-expressions) to."
3698 msgstr ""
3699
3700 #. type: Plain text
3701 #: doc/rust.md:1918
3702 msgid ""
3703 "When the type of the expression to the left of the dot is a pointer to a "
3704 "record or structure, it is automatically derferenced to make the field "
3705 "access possible."
3706 msgstr ""
3707
3708 #. type: Plain text
3709 #: doc/rust.md:1921
3710 msgid "### Vector expressions"
3711 msgstr ""
3712
3713 #. type: Plain text
3714 #: doc/rust.md:1924
3715 msgid "~~~~~~~~{.ebnf .gram} vec_expr : '[' \"mut\"? vec_elems? ']'"
3716 msgstr ""
3717
3718 #. type: Plain text
3719 #: doc/rust.md:1927
3720 msgid "vec_elems : [expr [',' expr]*] | [expr ',' \"..\" expr] ~~~~~~~~"
3721 msgstr ""
3722
3723 #. type: Plain text
3724 #: doc/rust.md:1930
3725 msgid ""
3726 "A [_vector_](#vector-types) _expression_ is written by enclosing zero or "
3727 "more comma-separated expressions of uniform type in square brackets."
3728 msgstr ""
3729
3730 #. type: Plain text
3731 #: doc/rust.md:1934
3732 msgid ""
3733 "In the `[expr ',' \"..\" expr]` form, the expression after the `\"..\"` must "
3734 "be a constant expression that can be evaluated at compile time, such as a "
3735 "[literal](#literals) or a [static item](#static-items)."
3736 msgstr ""
3737
3738 #. type: Plain text
3739 #: doc/rust.md:1941
3740 #, no-wrap
3741 msgid ""
3742 "~~~~\n"
3743 "[1, 2, 3, 4];\n"
3744 "[\"a\", \"b\", \"c\", \"d\"];\n"
3745 "[0, ..128];             // vector with 128 zeros\n"
3746 "[0u8, 0u8, 0u8, 0u8];\n"
3747 "~~~~\n"
3748 msgstr ""
3749
3750 #. type: Plain text
3751 #: doc/rust.md:1943
3752 msgid "### Index expressions"
3753 msgstr ""
3754
3755 #. type: Plain text
3756 #: doc/rust.md:1947
3757 msgid "~~~~~~~~{.ebnf .gram} idx_expr : expr '[' expr ']' ~~~~~~~~"
3758 msgstr ""
3759
3760 #. type: Plain text
3761 #: doc/rust.md:1952
3762 msgid ""
3763 "[Vector](#vector-types)-typed expressions can be indexed by writing a square-"
3764 "bracket-enclosed expression (the index) after them. When the vector is "
3765 "mutable, the resulting [lvalue](#lvalues-rvalues-and-temporaries) can be "
3766 "assigned to."
3767 msgstr ""
3768
3769 #. type: Plain text
3770 #: doc/rust.md:1956
3771 msgid ""
3772 "Indices are zero-based, and may be of any integral type. Vector access is "
3773 "bounds-checked at run-time. When the check fails, it will put the task in a "
3774 "_failing state_."
3775 msgstr ""
3776
3777 #. type: Plain text
3778 #: doc/rust.md:1960
3779 msgid "~~~~ # use std::task; # do task::spawn_unlinked {"
3780 msgstr ""
3781
3782 #. type: Plain text
3783 #: doc/rust.md:1963
3784 msgid "([1, 2, 3, 4])[0]; ([\"a\", \"b\"])[10]; // fails"
3785 msgstr ""
3786
3787 #. type: Plain text
3788 #: doc/rust.md:1966 doc/tutorial-tasks.md:648
3789 msgid "# } ~~~~"
3790 msgstr ""
3791
3792 #. type: Plain text
3793 #: doc/rust.md:1968
3794 msgid "### Unary operator expressions"
3795 msgstr ""
3796
3797 #. type: Plain text
3798 #: doc/rust.md:1972
3799 msgid ""
3800 "Rust defines six symbolic unary operators.  They are all written as prefix "
3801 "operators, before the expression they apply to."
3802 msgstr ""
3803
3804 #. type: Plain text
3805 #: doc/rust.md:1991
3806 #, no-wrap
3807 msgid ""
3808 "`-`\n"
3809 "  : Negation. May only be applied to numeric types.\n"
3810 "`*`\n"
3811 "  : Dereference. When applied to a [pointer](#pointer-types) it denotes the pointed-to location.\n"
3812 "    For pointers to mutable locations, the resulting [lvalue](#lvalues-rvalues-and-temporaries) can be assigned to.\n"
3813 "    For [enums](#enumerated-types) that have only a single variant, containing a single parameter,\n"
3814 "    the dereference operator accesses this parameter.\n"
3815 "`!`\n"
3816 "  : Logical negation. On the boolean type, this flips between `true` and\n"
3817 "    `false`. On integer types, this inverts the individual bits in the\n"
3818 "    two's complement representation of the value.\n"
3819 "`@` and `~`\n"
3820 "  :  [Boxing](#pointer-types) operators. Allocate a box to hold the value they are applied to,\n"
3821 "     and store the value in it. `@` creates a managed box, whereas `~` creates an owned box.\n"
3822 "`&`\n"
3823 "  : Borrow operator. Returns a borrowed pointer, pointing to its operand.\n"
3824 "    The operand of a borrowed pointer is statically proven to outlive the resulting pointer.\n"
3825 "    If the borrow-checker cannot prove this, it is a compilation error.\n"
3826 msgstr ""
3827
3828 #. type: Plain text
3829 #: doc/rust.md:1993
3830 msgid "### Binary operator expressions"
3831 msgstr ""
3832
3833 #. type: Plain text
3834 #: doc/rust.md:1997
3835 msgid "~~~~~~~~{.ebnf .gram} binop_expr : expr binop expr ; ~~~~~~~~"
3836 msgstr ""
3837
3838 #. type: Plain text
3839 #: doc/rust.md:2000
3840 msgid ""
3841 "Binary operators expressions are given in terms of [operator precedence]"
3842 "(#operator-precedence)."
3843 msgstr ""
3844
3845 #. type: Plain text
3846 #: doc/rust.md:2002
3847 msgid "#### Arithmetic operators"
3848 msgstr ""
3849
3850 #. type: Plain text
3851 #: doc/rust.md:2007
3852 msgid ""
3853 "Binary arithmetic expressions are syntactic sugar for calls to built-in "
3854 "traits, defined in the `std::ops` module of the `std` library.  This means "
3855 "that arithmetic operators can be overridden for user-defined types.  The "
3856 "default meaning of the operators on standard types is given here."
3857 msgstr ""
3858
3859 #. type: Plain text
3860 #: doc/rust.md:2023
3861 #, no-wrap
3862 msgid ""
3863 "`+`\n"
3864 "  : Addition and vector/string concatenation.\n"
3865 "    Calls the `add` method on the `std::ops::Add` trait.\n"
3866 "`-`\n"
3867 "  : Subtraction.\n"
3868 "    Calls the `sub` method on the `std::ops::Sub` trait.\n"
3869 "`*`\n"
3870 "  : Multiplication.\n"
3871 "    Calls the `mul` method on the `std::ops::Mul` trait.\n"
3872 "`/`\n"
3873 "  : Quotient.\n"
3874 "    Calls the `div` method on the `std::ops::Div` trait.\n"
3875 "`%`\n"
3876 "  : Remainder.\n"
3877 "    Calls the `rem` method on the `std::ops::Rem` trait.\n"
3878 msgstr ""
3879
3880 #. type: Plain text
3881 #: doc/rust.md:2025
3882 msgid "#### Bitwise operators"
3883 msgstr ""
3884
3885 #. type: Plain text
3886 #: doc/rust.md:2030
3887 msgid ""
3888 "Like the [arithmetic operators](#arithmetic-operators), bitwise operators "
3889 "are syntactic sugar for calls to methods of built-in traits.  This means "
3890 "that bitwise operators can be overridden for user-defined types.  The "
3891 "default meaning of the operators on standard types is given here."
3892 msgstr ""
3893
3894 #. type: Plain text
3895 #: doc/rust.md:2046
3896 #, no-wrap
3897 msgid ""
3898 "`&`\n"
3899 "  : And.\n"
3900 "    Calls the `bitand` method of the `std::ops::BitAnd` trait.\n"
3901 "`|`\n"
3902 "  : Inclusive or.\n"
3903 "    Calls the `bitor` method of the `std::ops::BitOr` trait.\n"
3904 "`^`\n"
3905 "  : Exclusive or.\n"
3906 "    Calls the `bitxor` method of the `std::ops::BitXor` trait.\n"
3907 "`<<`\n"
3908 "  : Logical left shift.\n"
3909 "    Calls the `shl` method of the `std::ops::Shl` trait.\n"
3910 "`>>`\n"
3911 "  : Logical right shift.\n"
3912 "    Calls the `shr` method of the `std::ops::Shr` trait.\n"
3913 msgstr ""
3914
3915 #. type: Plain text
3916 #: doc/rust.md:2048
3917 msgid "#### Lazy boolean operators"
3918 msgstr ""
3919
3920 #. type: Plain text
3921 #: doc/rust.md:2055
3922 msgid ""
3923 "The operators `||` and `&&` may be applied to operands of boolean type.  The "
3924 "`||` operator denotes logical 'or', and the `&&` operator denotes logical "
3925 "'and'.  They differ from `|` and `&` in that the right-hand operand is only "
3926 "evaluated when the left-hand operand does not already determine the result "
3927 "of the expression.  That is, `||` only evaluates its right-hand operand when "
3928 "the left-hand operand evaluates to `false`, and `&&` only when it evaluates "
3929 "to `true`."
3930 msgstr ""
3931
3932 #. type: Plain text
3933 #: doc/rust.md:2057
3934 msgid "#### Comparison operators"
3935 msgstr ""
3936
3937 #. type: Plain text
3938 #: doc/rust.md:2063
3939 msgid ""
3940 "Comparison operators are, like the [arithmetic operators](#arithmetic-"
3941 "operators), and [bitwise operators](#bitwise-operators), syntactic sugar for "
3942 "calls to built-in traits.  This means that comparison operators can be "
3943 "overridden for user-defined types.  The default meaning of the operators on "
3944 "standard types is given here."
3945 msgstr ""
3946
3947 #. type: Plain text
3948 #: doc/rust.md:2082
3949 #, no-wrap
3950 msgid ""
3951 "`==`\n"
3952 "  : Equal to.\n"
3953 "    Calls the `eq` method on the `std::cmp::Eq` trait.\n"
3954 "`!=`\n"
3955 "  : Unequal to.\n"
3956 "    Calls the `ne` method on the `std::cmp::Eq` trait.\n"
3957 "`<`\n"
3958 "  : Less than.\n"
3959 "    Calls the `lt` method on the `std::cmp::Ord` trait.\n"
3960 "`>`\n"
3961 "  : Greater than.\n"
3962 "    Calls the `gt` method on the `std::cmp::Ord` trait.\n"
3963 "`<=`\n"
3964 "  : Less than or equal.\n"
3965 "    Calls the `le` method on the `std::cmp::Ord` trait.\n"
3966 "`>=`\n"
3967 "  : Greater than or equal.\n"
3968 "    Calls the `ge` method on the `std::cmp::Ord` trait.\n"
3969 msgstr ""
3970
3971 #. type: Plain text
3972 #: doc/rust.md:2085
3973 msgid "#### Type cast expressions"
3974 msgstr ""
3975
3976 #. type: Plain text
3977 #: doc/rust.md:2087
3978 msgid "A type cast expression is denoted with the binary operator `as`."
3979 msgstr ""
3980
3981 #. type: Plain text
3982 #: doc/rust.md:2090
3983 msgid ""
3984 "Executing an `as` expression casts the value on the left-hand side to the "
3985 "type on the right-hand side."
3986 msgstr ""
3987
3988 #. type: Plain text
3989 #: doc/rust.md:2094
3990 msgid ""
3991 "A numeric value can be cast to any numeric type.  A raw pointer value can be "
3992 "cast to or from any integral type or raw pointer type.  Any other cast is "
3993 "unsupported and will fail to compile."
3994 msgstr ""
3995
3996 #. type: Plain text
3997 #: doc/rust.md:2096
3998 msgid "An example of an `as` expression:"
3999 msgstr ""
4000
4001 #. type: Plain text
4002 #: doc/rust.md:2100
4003 msgid ""
4004 "~~~~ # fn sum(v: &[float]) -> float { 0.0 } # fn len(v: &[float]) -> int "
4005 "{ 0 }"
4006 msgstr ""
4007
4008 #. type: Plain text
4009 #: doc/rust.md:2107
4010 #, no-wrap
4011 msgid ""
4012 "fn avg(v: &[float]) -> float {\n"
4013 "  let sum: float = sum(v);\n"
4014 "  let sz: float = len(v) as float;\n"
4015 "  return sum / sz;\n"
4016 "}\n"
4017 "~~~~\n"
4018 msgstr ""
4019
4020 #. type: Plain text
4021 #: doc/rust.md:2109
4022 msgid "#### Assignment expressions"
4023 msgstr ""
4024
4025 #. type: Plain text
4026 #: doc/rust.md:2112
4027 msgid ""
4028 "An _assignment expression_ consists of an [lvalue](#lvalues-rvalues-and-"
4029 "temporaries) expression followed by an equals sign (`=`) and an [rvalue]"
4030 "(#lvalues-rvalues-and-temporaries) expression."
4031 msgstr ""
4032
4033 #. type: Plain text
4034 #: doc/rust.md:2114
4035 msgid ""
4036 "Evaluating an assignment expression [either copies or moves](#moved-and-"
4037 "copied-types) its right-hand operand to its left-hand operand."
4038 msgstr ""
4039
4040 #. type: Plain text
4041 #: doc/rust.md:2118
4042 msgid "~~~~ # let mut x = 0; # let y = 0;"
4043 msgstr ""
4044
4045 #. type: Plain text
4046 #: doc/rust.md:2121
4047 msgid "x = y; ~~~~"
4048 msgstr ""
4049
4050 #. type: Plain text
4051 #: doc/rust.md:2123
4052 msgid "#### Compound assignment expressions"
4053 msgstr ""
4054
4055 #. type: Plain text
4056 #: doc/rust.md:2128
4057 msgid ""
4058 "The `+`, `-`, `*`, `/`, `%`, `&`, `|`, `^`, `<<`, and `>>` operators may be "
4059 "composed with the `=` operator. The expression `lval OP= val` is equivalent "
4060 "to `lval = lval OP val`. For example, `x = x + 1` may be written as `x += 1`."
4061 msgstr ""
4062
4063 #. type: Plain text
4064 #: doc/rust.md:2130
4065 msgid "Any such expression always has the [`unit`](#primitive-types) type."
4066 msgstr ""
4067
4068 #. type: Plain text
4069 #: doc/rust.md:2132
4070 msgid "#### Operator precedence"
4071 msgstr ""
4072
4073 #. type: Plain text
4074 #: doc/rust.md:2135
4075 msgid ""
4076 "The precedence of Rust binary operators is ordered as follows, going from "
4077 "strong to weak:"
4078 msgstr ""
4079
4080 #. type: Plain text
4081 #: doc/rust.md:2148
4082 #, no-wrap
4083 msgid ""
4084 "~~~~ {.precedence}\n"
4085 "* / %\n"
4086 "as\n"
4087 "+ -\n"
4088 "<< >>\n"
4089 "&\n"
4090 "^\n"
4091 "|\n"
4092 "< > <= >=\n"
4093 "== !=\n"
4094 "&&\n"
4095 "||\n"
4096 "=\n"
4097 msgstr ""
4098
4099 #. type: Plain text
4100 #: doc/rust.md:2150 doc/rust.md:2237 doc/tutorial-macros.md:323
4101 msgid "~~~~"
4102 msgstr ""
4103
4104 #. type: Plain text
4105 #: doc/rust.md:2153
4106 msgid ""
4107 "Operators at the same precedence level are evaluated left-to-right. [Unary "
4108 "operators](#unary-operator-expressions)  have the same precedence level and "
4109 "it is stronger than any of the binary operators'."
4110 msgstr ""
4111
4112 #. type: Plain text
4113 #: doc/rust.md:2155
4114 msgid "### Grouped expressions"
4115 msgstr ""
4116
4117 #. type: Plain text
4118 #: doc/rust.md:2159
4119 msgid ""
4120 "An expression enclosed in parentheses evaluates to the result of the "
4121 "enclosed expression.  Parentheses can be used to explicitly specify "
4122 "evaluation order within an expression."
4123 msgstr ""
4124
4125 #. type: Plain text
4126 #: doc/rust.md:2163
4127 msgid "~~~~~~~~{.ebnf .gram} paren_expr : '(' expr ')' ; ~~~~~~~~"
4128 msgstr ""
4129
4130 #. type: Plain text
4131 #: doc/rust.md:2165
4132 msgid "An example of a parenthesized expression:"
4133 msgstr ""
4134
4135 #. type: Plain text
4136 #: doc/rust.md:2169
4137 msgid "~~~~ let x = (2 + 3) * 4; ~~~~"
4138 msgstr ""
4139
4140 #. type: Plain text
4141 #: doc/rust.md:2172
4142 msgid "### Call expressions"
4143 msgstr ""
4144
4145 #. type: Plain text
4146 #: doc/rust.md:2178
4147 msgid ""
4148 "~~~~~~~~ {.abnf .gram} expr_list : [ expr [ ',' expr ]* ] ? ; "
4149 "paren_expr_list : '(' expr_list ')' ; call_expr : expr paren_expr_list ; "
4150 "~~~~~~~~"
4151 msgstr ""
4152
4153 #. type: Plain text
4154 #: doc/rust.md:2183
4155 msgid ""
4156 "A _call expression_ invokes a function, providing zero or more input slots "
4157 "and an optional reference slot to serve as the function's output, bound to "
4158 "the `lval` on the right hand side of the call. If the function eventually "
4159 "returns, then the expression completes."
4160 msgstr ""
4161
4162 #. type: Plain text
4163 #: doc/rust.md:2185
4164 msgid "Some examples of call expressions:"
4165 msgstr ""
4166
4167 #. type: Plain text
4168 #: doc/rust.md:2189
4169 msgid ""
4170 "~~~~ # use std::from_str::FromStr; # fn add(x: int, y: int) -> int { 0 }"
4171 msgstr ""
4172
4173 #. type: Plain text
4174 #: doc/rust.md:2193
4175 msgid ""
4176 "let x: int = add(1, 2); let pi = FromStr::from_str::<f32>(\"3.14\"); ~~~~"
4177 msgstr ""
4178
4179 #. type: Plain text
4180 #: doc/rust.md:2195
4181 msgid "### Lambda expressions"
4182 msgstr ""
4183
4184 #. type: Plain text
4185 #: doc/rust.md:2200
4186 msgid ""
4187 "~~~~~~~~ {.abnf .gram} ident_list : [ ident [ ',' ident ]* ] ? ; "
4188 "lambda_expr : '|' ident_list '|' expr ; ~~~~~~~~"
4189 msgstr ""
4190
4191 #. type: Plain text
4192 #: doc/rust.md:2204
4193 msgid ""
4194 "A _lambda expression_ (sometimes called an \"anonymous function expression"
4195 "\") defines a function and denotes it as a value, in a single expression.  A "
4196 "lambda expression is a pipe-symbol-delimited (`|`) list of identifiers "
4197 "followed by an expression."
4198 msgstr ""
4199
4200 #. type: Plain text
4201 #: doc/rust.md:2209
4202 msgid ""
4203 "A lambda expression denotes a function that maps a list of parameters "
4204 "(`ident_list`)  onto the expression that follows the `ident_list`.  The "
4205 "identifiers in the `ident_list` are the parameters to the function.  These "
4206 "parameters' types need not be specified, as the compiler infers them from "
4207 "context."
4208 msgstr ""
4209
4210 #. type: Plain text
4211 #: doc/rust.md:2212
4212 msgid ""
4213 "Lambda expressions are most useful when passing functions as arguments to "
4214 "other functions, as an abbreviation for defining and capturing a separate "
4215 "function."
4216 msgstr ""
4217
4218 #. type: Plain text
4219 #: doc/rust.md:2221
4220 msgid ""
4221 "Significantly, lambda expressions _capture their environment_, which regular "
4222 "[function definitions](#functions) do not.  The exact type of capture "
4223 "depends on the [function type](#function-types) inferred for the lambda "
4224 "expression.  In the simplest and least-expensive form (analogous to a "
4225 "```&fn() { }``` expression), the lambda expression captures its environment "
4226 "by reference, effectively borrowing pointers to all outer variables "
4227 "mentioned inside the function.  Alternately, the compiler may infer that a "
4228 "lambda expression should copy or move values (depending on their type.)  "
4229 "from the environment into the lambda expression's captured environment."
4230 msgstr ""
4231
4232 #. type: Plain text
4233 #: doc/rust.md:2224
4234 msgid ""
4235 "In this example, we define a function `ten_times` that takes a higher-order "
4236 "function argument, and call it with a lambda expression as an argument."
4237 msgstr ""
4238
4239 #. type: Plain text
4240 #: doc/rust.md:2233
4241 #, no-wrap
4242 msgid ""
4243 "~~~~\n"
4244 "fn ten_times(f: &fn(int)) {\n"
4245 "    let mut i = 0;\n"
4246 "    while i < 10 {\n"
4247 "        f(i);\n"
4248 "        i += 1;\n"
4249 "    }\n"
4250 "}\n"
4251 msgstr ""
4252
4253 #. type: Plain text
4254 #: doc/rust.md:2235
4255 msgid "ten_times(|j| println(fmt!(\"hello, %d\", j)));"
4256 msgstr ""
4257
4258 #. type: Plain text
4259 #: doc/rust.md:2239
4260 msgid "### While loops"
4261 msgstr ""
4262
4263 #. type: Plain text
4264 #: doc/rust.md:2243
4265 msgid ""
4266 "~~~~~~~~{.ebnf .gram} while_expr : \"while\" expr '{' block '}' ; ~~~~~~~~"
4267 msgstr ""
4268
4269 #. type: Plain text
4270 #: doc/rust.md:2248
4271 msgid ""
4272 "A `while` loop begins by evaluating the boolean loop conditional "
4273 "expression.  If the loop conditional expression evaluates to `true`, the "
4274 "loop body block executes and control returns to the loop conditional "
4275 "expression. If the loop conditional expression evaluates to `false`, the "
4276 "`while` expression completes."
4277 msgstr ""
4278
4279 #. type: Plain text
4280 #: doc/rust.md:2250
4281 msgid "An example:"
4282 msgstr ""
4283
4284 #. type: Plain text
4285 #: doc/rust.md:2253
4286 msgid "~~~~ let mut i = 0;"
4287 msgstr ""
4288
4289 #. type: Plain text
4290 #: doc/rust.md:2259
4291 #, no-wrap
4292 msgid ""
4293 "while i < 10 {\n"
4294 "    println(\"hello\\n\");\n"
4295 "    i = i + 1;\n"
4296 "}\n"
4297 "~~~~\n"
4298 msgstr ""
4299
4300 #. type: Plain text
4301 #: doc/rust.md:2261
4302 msgid "### Infinite loops"
4303 msgstr ""
4304
4305 #. type: Plain text
4306 #: doc/rust.md:2265
4307 msgid ""
4308 "The keyword `loop` in Rust appears both in _loop expressions_ and in "
4309 "_continue expressions_.  A loop expression denotes an infinite loop; see "
4310 "[Continue expressions](#continue-expressions) for continue expressions."
4311 msgstr ""
4312
4313 #. type: Plain text
4314 #: doc/rust.md:2269
4315 msgid ""
4316 "~~~~~~~~{.ebnf .gram} loop_expr : [ lifetime ':' ] \"loop\" '{' block '}'; "
4317 "~~~~~~~~"
4318 msgstr ""
4319
4320 #. type: Plain text
4321 #: doc/rust.md:2274
4322 msgid ""
4323 "A `loop` expression may optionally have a _label_.  If a label is present, "
4324 "then labeled `break` and `loop` expressions nested within this loop may exit "
4325 "out of this loop or return control to its head.  See [Break expressions]"
4326 "(#break-expressions)."
4327 msgstr ""
4328
4329 #. type: Plain text
4330 #: doc/rust.md:2276
4331 msgid "### Break expressions"
4332 msgstr ""
4333
4334 #. type: Plain text
4335 #: doc/rust.md:2280
4336 msgid "~~~~~~~~{.ebnf .gram} break_expr : \"break\" [ lifetime ]; ~~~~~~~~"
4337 msgstr ""
4338
4339 #. type: Plain text
4340 #: doc/rust.md:2287
4341 msgid ""
4342 "A `break` expression has an optional `label`.  If the label is absent, then "
4343 "executing a `break` expression immediately terminates the innermost loop "
4344 "enclosing it.  It is only permitted in the body of a loop.  If the label is "
4345 "present, then `break foo` terminates the loop with label `foo`, which need "
4346 "not be the innermost label enclosing the `break` expression, but must "
4347 "enclose it."
4348 msgstr ""
4349
4350 #. type: Plain text
4351 #: doc/rust.md:2289
4352 msgid "### Continue expressions"
4353 msgstr ""
4354
4355 #. type: Plain text
4356 #: doc/rust.md:2293
4357 msgid "~~~~~~~~{.ebnf .gram} continue_expr : \"loop\" [ lifetime ]; ~~~~~~~~"
4358 msgstr ""
4359
4360 #. type: Plain text
4361 #: doc/rust.md:2304
4362 msgid ""
4363 "A continue expression, written `loop`, also has an optional `label`.  If the "
4364 "label is absent, then executing a `loop` expression immediately terminates "
4365 "the current iteration of the innermost loop enclosing it, returning control "
4366 "to the loop *head*.  In the case of a `while` loop, the head is the "
4367 "conditional expression controlling the loop.  In the case of a `for` loop, "
4368 "the head is the call-expression controlling the loop.  If the label is "
4369 "present, then `loop foo` returns control to the head of the loop with label "
4370 "`foo`, which need not be the innermost label enclosing the `break` "
4371 "expression, but must enclose it."
4372 msgstr ""
4373
4374 #. type: Plain text
4375 #: doc/rust.md:2306
4376 msgid "A `loop` expression is only permitted in the body of a loop."
4377 msgstr ""
4378
4379 #. type: Plain text
4380 #: doc/rust.md:2309
4381 msgid "### Do expressions"
4382 msgstr ""
4383
4384 #. type: Plain text
4385 #: doc/rust.md:2313
4386 msgid ""
4387 "~~~~~~~~{.ebnf .gram} do_expr : \"do\" expr [ '|' ident_list '|' ] ? '{' "
4388 "block '}' ; ~~~~~~~~"
4389 msgstr ""
4390
4391 #. type: Plain text
4392 #: doc/rust.md:2316
4393 msgid ""
4394 "A _do expression_ provides a more-familiar block-syntax for a [lambda "
4395 "expression](#lambda-expressions), including a special translation of [return "
4396 "expressions](#return-expressions) inside the supplied block."
4397 msgstr ""
4398
4399 #. type: Plain text
4400 #: doc/rust.md:2324
4401 msgid ""
4402 "Any occurrence of a [return expression](#return-expressions)  inside this "
4403 "`block` expression is rewritten as a reference to an (anonymous) flag set in "
4404 "the caller's environment, which is checked on return from the `expr` and, if "
4405 "set, causes a corresponding return from the caller.  In this way, the "
4406 "meaning of `return` statements in language built-in control blocks is "
4407 "preserved, if they are rewritten using lambda functions and `do` expressions "
4408 "as abstractions."
4409 msgstr ""
4410
4411 #. type: Plain text
4412 #: doc/rust.md:2327
4413 msgid ""
4414 "The optional `ident_list` and `block` provided in a `do` expression are "
4415 "parsed as though they constitute a lambda expression; if the `ident_list` is "
4416 "missing, an empty `ident_list` is implied."
4417 msgstr ""
4418
4419 #. type: Plain text
4420 #: doc/rust.md:2333
4421 msgid ""
4422 "The lambda expression is then provided as a _trailing argument_ to the "
4423 "outermost [call](#call-expressions) or [method call](#method-call-"
4424 "expressions) expression in the `expr` following `do`.  If the `expr` is a "
4425 "[path expression](#path-expressions), it is parsed as though it is a call "
4426 "expression.  If the `expr` is a [field expression](#field-expressions), it "
4427 "is parsed as though it is a method call expression."
4428 msgstr ""
4429
4430 #. type: Plain text
4431 #: doc/rust.md:2335
4432 msgid "In this example, both calls to `f` are equivalent:"
4433 msgstr ""
4434
4435 #. type: Plain text
4436 #: doc/rust.md:2339
4437 msgid "~~~~ # fn f(f: &fn(int)) { } # fn g(i: int) { }"
4438 msgstr ""
4439
4440 #. type: Plain text
4441 #: doc/rust.md:2341
4442 msgid "f(|j| g(j));"
4443 msgstr ""
4444
4445 #. type: Plain text
4446 #: doc/rust.md:2346
4447 #, no-wrap
4448 msgid ""
4449 "do f |j| {\n"
4450 "    g(j);\n"
4451 "}\n"
4452 "~~~~\n"
4453 msgstr ""
4454
4455 #. type: Plain text
4456 #: doc/rust.md:2348
4457 msgid ""
4458 "In this example, both calls to the (binary) function `k` are equivalent:"
4459 msgstr ""
4460
4461 #. type: Plain text
4462 #: doc/rust.md:2352
4463 msgid "~~~~ # fn k(x:int, f: &fn(int)) { } # fn l(i: int) { }"
4464 msgstr ""
4465
4466 #. type: Plain text
4467 #: doc/rust.md:2354
4468 msgid "k(3, |j| l(j));"
4469 msgstr ""
4470
4471 #. type: Plain text
4472 #: doc/rust.md:2359
4473 #, no-wrap
4474 msgid ""
4475 "do k(3) |j| {\n"
4476 "   l(j);\n"
4477 "}\n"
4478 "~~~~\n"
4479 msgstr ""
4480
4481 #. type: Plain text
4482 #: doc/rust.md:2362
4483 msgid "### For expressions"
4484 msgstr ""
4485
4486 #. type: Plain text
4487 #: doc/rust.md:2366
4488 msgid ""
4489 "~~~~~~~~{.ebnf .gram} for_expr : \"for\" expr [ '|' ident_list '|' ] ? '{' "
4490 "block '}' ; ~~~~~~~~"
4491 msgstr ""
4492
4493 #. type: Plain text
4494 #: doc/rust.md:2370
4495 msgid ""
4496 "A _for expression_ is similar to a [`do` expression](#do-expressions), in "
4497 "that it provides a special block-form of lambda expression, suited to "
4498 "passing the `block` function to a higher-order function implementing a loop."
4499 msgstr ""
4500
4501 #. type: Plain text
4502 #: doc/rust.md:2376
4503 msgid ""
4504 "In contrast to a `do` expression, a `for` expression is designed to work "
4505 "with methods such as `each` and `times`, that require the body block to "
4506 "return a boolean. The `for` expression accommodates this by implicitly "
4507 "returning `true` at the end of each block, unless a `break` expression is "
4508 "evaluated."
4509 msgstr ""
4510
4511 #. type: Plain text
4512 #: doc/rust.md:2383
4513 msgid ""
4514 "In addition, [`break`](#break-expressions) and [`loop`](#loop-expressions) "
4515 "expressions are rewritten inside `for` expressions in the same way that "
4516 "`return` expressions are, with a combination of local flag variables, and "
4517 "early boolean-valued returns from the `block` function, such that the "
4518 "meaning of `break` and `loop` is preserved in a primitive loop when "
4519 "rewritten as a `for` loop controlled by a higher order function."
4520 msgstr ""
4521
4522 #. type: Plain text
4523 #: doc/rust.md:2385
4524 msgid "An example of a for loop over the contents of a vector:"
4525 msgstr ""
4526
4527 #. type: Plain text
4528 #: doc/rust.md:2392
4529 msgid ""
4530 "~~~~ # type foo = int; # fn bar(f: foo) { } # let a = 0; # let b = 0; # let "
4531 "c = 0;"
4532 msgstr ""
4533
4534 #. type: Plain text
4535 #: doc/rust.md:2394
4536 msgid "let v: &[foo] = &[a, b, c];"
4537 msgstr ""
4538
4539 #. type: Plain text
4540 #: doc/rust.md:2399
4541 #, no-wrap
4542 msgid ""
4543 "for e in v.iter() {\n"
4544 "    bar(*e);\n"
4545 "}\n"
4546 "~~~~\n"
4547 msgstr ""
4548
4549 #. type: Plain text
4550 #: doc/rust.md:2401
4551 msgid "An example of a for loop over a series of integers:"
4552 msgstr ""
4553
4554 #. type: Plain text
4555 #: doc/rust.md:2408
4556 #, no-wrap
4557 msgid ""
4558 "~~~~\n"
4559 "# fn bar(b:uint) { }\n"
4560 "for i in range(0u, 256) {\n"
4561 "    bar(i);\n"
4562 "}\n"
4563 "~~~~\n"
4564 msgstr ""
4565
4566 #. type: Plain text
4567 #: doc/rust.md:2410
4568 msgid "### If expressions"
4569 msgstr ""
4570
4571 #. type: Plain text
4572 #: doc/rust.md:2414
4573 #, no-wrap
4574 msgid ""
4575 "~~~~~~~~{.ebnf .gram}\n"
4576 "if_expr : \"if\" expr '{' block '}'\n"
4577 "          else_tail ? ;\n"
4578 msgstr ""
4579
4580 #. type: Plain text
4581 #: doc/rust.md:2418
4582 #, no-wrap
4583 msgid ""
4584 "else_tail : \"else\" [ if_expr\n"
4585 "                   | '{' block '}' ] ;\n"
4586 "~~~~~~~~\n"
4587 msgstr ""
4588
4589 #. type: Plain text
4590 #: doc/rust.md:2429
4591 msgid ""
4592 "An `if` expression is a conditional branch in program control. The form of "
4593 "an `if` expression is a condition expression, followed by a consequent "
4594 "block, any number of `else if` conditions and blocks, and an optional "
4595 "trailing `else` block. The condition expressions must have type `bool`. If a "
4596 "condition expression evaluates to `true`, the consequent block is executed "
4597 "and any subsequent `else if` or `else` block is skipped. If a condition "
4598 "expression evaluates to `false`, the consequent block is skipped and any "
4599 "subsequent `else if` condition is evaluated. If all `if` and `else if` "
4600 "conditions evaluate to `false` then any `else` block is executed."
4601 msgstr ""
4602
4603 #. type: Plain text
4604 #: doc/rust.md:2432
4605 msgid "### Match expressions"
4606 msgstr ""
4607
4608 #. type: Plain text
4609 #: doc/rust.md:2435
4610 msgid ""
4611 "~~~~~~~~{.ebnf .gram} match_expr : \"match\" expr '{' match_arm [ '|' "
4612 "match_arm ] * '}' ;"
4613 msgstr ""
4614
4615 #. type: Plain text
4616 #: doc/rust.md:2437
4617 msgid "match_arm : match_pat '=>' [ expr \",\" | '{' block '}' ] ;"
4618 msgstr ""
4619
4620 #. type: Plain text
4621 #: doc/rust.md:2440
4622 msgid "match_pat : pat [ \"..\" pat ] ? [ \"if\" expr ] ; ~~~~~~~~"
4623 msgstr ""
4624
4625 #. type: Plain text
4626 #: doc/rust.md:2448
4627 msgid ""
4628 "A `match` expression branches on a *pattern*. The exact form of matching "
4629 "that occurs depends on the pattern. Patterns consist of some combination of "
4630 "literals, destructured enum constructors, structures, records and tuples, "
4631 "variable binding specifications, wildcards (`*`), and placeholders (`_`). A "
4632 "`match` expression has a *head expression*, which is the value to compare to "
4633 "the patterns. The type of the patterns must equal the type of the head "
4634 "expression."
4635 msgstr ""
4636
4637 #. type: Plain text
4638 #: doc/rust.md:2452
4639 msgid ""
4640 "In a pattern whose head expression has an `enum` type, a placeholder (`_`) "
4641 "stands for a *single* data field, whereas a wildcard `*` stands for *all* "
4642 "the fields of a particular variant. For example:"
4643 msgstr ""
4644
4645 #. type: Plain text
4646 #: doc/rust.md:2455
4647 msgid "~~~~ enum List<X> { Nil, Cons(X, @List<X>) }"
4648 msgstr ""
4649
4650 #. type: Plain text
4651 #: doc/rust.md:2457 doc/rust.md:2486
4652 msgid "let x: List<int> = Cons(10, @Cons(11, @Nil));"
4653 msgstr ""
4654
4655 #. type: Plain text
4656 #: doc/rust.md:2464
4657 #, no-wrap
4658 msgid ""
4659 "match x {\n"
4660 "    Cons(_, @Nil) => fail!(\"singleton list\"),\n"
4661 "    Cons(*)       => return,\n"
4662 "    Nil           => fail!(\"empty list\")\n"
4663 "}\n"
4664 "~~~~\n"
4665 msgstr ""
4666
4667 #. type: Plain text
4668 #: doc/rust.md:2469
4669 msgid ""
4670 "The first pattern matches lists constructed by applying `Cons` to any head "
4671 "value, and a tail value of `@Nil`. The second pattern matches _any_ list "
4672 "constructed with `Cons`, ignoring the values of its arguments. The "
4673 "difference between `_` and `*` is that the pattern `C(_)` is only type-"
4674 "correct if `C` has exactly one argument, while the pattern `C(*)` is type-"
4675 "correct for any enum variant `C`, regardless of how many arguments `C` has."
4676 msgstr ""
4677
4678 #. type: Plain text
4679 #: doc/rust.md:2475
4680 msgid ""
4681 "To execute an `match` expression, first the head expression is evaluated, "
4682 "then its value is sequentially compared to the patterns in the arms until a "
4683 "match is found. The first arm with a matching pattern is chosen as the "
4684 "branch target of the `match`, any variables bound by the pattern are "
4685 "assigned to local variables in the arm's block, and control enters the block."
4686 msgstr ""
4687
4688 #. type: Plain text
4689 #: doc/rust.md:2477
4690 msgid "An example of an `match` expression:"
4691 msgstr ""
4692
4693 #. type: Plain text
4694 #: doc/rust.md:2482
4695 msgid "~~~~ # fn process_pair(a: int, b: int) { } # fn process_ten() { }"
4696 msgstr ""
4697
4698 #. type: Plain text
4699 #: doc/rust.md:2484
4700 msgid "enum List<X> { Nil, Cons(X, @List<X>) }"
4701 msgstr ""
4702
4703 #. type: Plain text
4704 #: doc/rust.md:2502
4705 #, no-wrap
4706 msgid ""
4707 "match x {\n"
4708 "    Cons(a, @Cons(b, _)) => {\n"
4709 "        process_pair(a,b);\n"
4710 "    }\n"
4711 "    Cons(10, _) => {\n"
4712 "        process_ten();\n"
4713 "    }\n"
4714 "    Nil => {\n"
4715 "        return;\n"
4716 "    }\n"
4717 "    _ => {\n"
4718 "        fail!();\n"
4719 "    }\n"
4720 "}\n"
4721 "~~~~\n"
4722 msgstr ""
4723
4724 #. type: Plain text
4725 #: doc/rust.md:2509
4726 msgid ""
4727 "Patterns that bind variables default to binding to a copy or move of the "
4728 "matched value (depending on the matched value's type).  This can be changed "
4729 "to bind to a borrowed pointer by using the ```ref``` keyword, or to a "
4730 "mutable borrowed pointer using ```ref mut```."
4731 msgstr ""
4732
4733 #. type: Plain text
4734 #: doc/rust.md:2520
4735 msgid ""
4736 "A pattern that's just an identifier, like `Nil` in the previous answer, "
4737 "could either refer to an enum variant that's in scope, or bind a new "
4738 "variable.  The compiler resolves this ambiguity by forbidding variable "
4739 "bindings that occur in ```match``` patterns from shadowing names of variants "
4740 "that are in scope.  For example, wherever ```List``` is in scope, a "
4741 "```match``` pattern would not be able to bind ```Nil``` as a new name.  The "
4742 "compiler interprets a variable pattern `x` as a binding _only_ if there is "
4743 "no variant named `x` in scope.  A convention you can use to avoid conflicts "
4744 "is simply to name variants with upper-case letters, and local variables with "
4745 "lower-case letters."
4746 msgstr ""
4747
4748 #. type: Plain text
4749 #: doc/rust.md:2524
4750 msgid ""
4751 "Multiple match patterns may be joined with the `|` operator.  A range of "
4752 "values may be specified with `..`.  For example:"
4753 msgstr ""
4754
4755 #. type: Plain text
4756 #: doc/rust.md:2527
4757 msgid "~~~~ # let x = 2;"
4758 msgstr ""
4759
4760 #. type: Plain text
4761 #: doc/rust.md:2534
4762 #, no-wrap
4763 msgid ""
4764 "let message = match x {\n"
4765 "  0 | 1  => \"not many\",\n"
4766 "  2 .. 9 => \"a few\",\n"
4767 "  _      => \"lots\"\n"
4768 "};\n"
4769 "~~~~\n"
4770 msgstr ""
4771
4772 #. type: Plain text
4773 #: doc/rust.md:2538
4774 msgid ""
4775 "Range patterns only work on scalar types (like integers and characters; not "
4776 "like vectors and structs, which have sub-components).  A range pattern may "
4777 "not be a sub-range of another range pattern inside the same `match`."
4778 msgstr ""
4779
4780 #. type: Plain text
4781 #: doc/rust.md:2543
4782 msgid ""
4783 "Finally, match patterns can accept *pattern guards* to further refine the "
4784 "criteria for matching a case. Pattern guards appear after the pattern and "
4785 "consist of a bool-typed expression following the `if` keyword. A pattern "
4786 "guard may refer to the variables bound within the pattern they follow."
4787 msgstr ""
4788
4789 #. type: Plain text
4790 #: doc/rust.md:2548
4791 msgid ""
4792 "~~~~ # let maybe_digit = Some(0); # fn process_digit(i: int) { } # fn "
4793 "process_other(i: int) { }"
4794 msgstr ""
4795
4796 #. type: Plain text
4797 #: doc/rust.md:2555
4798 #, no-wrap
4799 msgid ""
4800 "let message = match maybe_digit {\n"
4801 "  Some(x) if x < 10 => process_digit(x),\n"
4802 "  Some(x) => process_other(x),\n"
4803 "  None => fail!()\n"
4804 "};\n"
4805 "~~~~\n"
4806 msgstr ""
4807
4808 #. type: Plain text
4809 #: doc/rust.md:2557
4810 msgid "### Return expressions"
4811 msgstr ""
4812
4813 #. type: Plain text
4814 #: doc/rust.md:2561
4815 msgid "~~~~~~~~{.ebnf .gram} return_expr : \"return\" expr ? ; ~~~~~~~~"
4816 msgstr ""
4817
4818 #. type: Plain text
4819 #: doc/rust.md:2566
4820 msgid ""
4821 "Return expressions are denoted with the keyword `return`. Evaluating a "
4822 "`return` expression moves its argument into the output slot of the current "
4823 "function, destroys the current function activation frame, and transfers "
4824 "control to the caller frame."
4825 msgstr ""
4826
4827 #. type: Plain text
4828 #: doc/rust.md:2568
4829 msgid "An example of a `return` expression:"
4830 msgstr ""
4831
4832 #. type: Plain text
4833 #: doc/rust.md:2577
4834 #, no-wrap
4835 msgid ""
4836 "~~~~\n"
4837 "fn max(a: int, b: int) -> int {\n"
4838 "   if a > b {\n"
4839 "      return a;\n"
4840 "   }\n"
4841 "   return b;\n"
4842 "}\n"
4843 "~~~~\n"
4844 msgstr ""
4845
4846 #. type: Plain text
4847 #: doc/rust.md:2580
4848 msgid "# Type system"
4849 msgstr ""
4850
4851 #. type: Plain text
4852 #: doc/rust.md:2582
4853 msgid "## Types"
4854 msgstr ""
4855
4856 #. type: Plain text
4857 #: doc/rust.md:2585
4858 msgid ""
4859 "Every slot, item and value in a Rust program has a type. The _type_ of a "
4860 "*value* defines the interpretation of the memory holding it."
4861 msgstr ""
4862
4863 #. type: Plain text
4864 #: doc/rust.md:2589
4865 msgid ""
4866 "Built-in types and type-constructors are tightly integrated into the "
4867 "language, in nontrivial ways that are not possible to emulate in user-"
4868 "defined types. User-defined types have limited capabilities."
4869 msgstr ""
4870
4871 #. type: Plain text
4872 #: doc/rust.md:2591
4873 msgid "### Primitive types"
4874 msgstr ""
4875
4876 #. type: Plain text
4877 #: doc/rust.md:2593
4878 msgid "The primitive types are the following:"
4879 msgstr ""
4880
4881 #. type: Bullet: '* '
4882 #: doc/rust.md:2599
4883 msgid ""
4884 "The \"unit\" type `()`, having the single \"unit\" value `()` (occasionally "
4885 "called \"nil\").  ^[The \"unit\" value `()` is *not* a sentinel \"null "
4886 "pointer\" value for reference slots; the \"unit\" type is the implicit "
4887 "return type from functions otherwise lacking a return type, and can be used "
4888 "in other contexts (such as message-sending or type-parametric code) as a "
4889 "zero-size type.]"
4890 msgstr ""
4891
4892 #. type: Bullet: '* '
4893 #: doc/rust.md:2599
4894 msgid "The boolean type `bool` with values `true` and `false`."
4895 msgstr ""
4896
4897 #. type: Bullet: '* '
4898 #: doc/rust.md:2599
4899 msgid "The machine types."
4900 msgstr ""
4901
4902 #. type: Bullet: '* '
4903 #: doc/rust.md:2599
4904 msgid "The machine-dependent integer and floating-point types."
4905 msgstr ""
4906
4907 #. type: Plain text
4908 #: doc/rust.md:2601
4909 msgid "#### Machine types"
4910 msgstr ""
4911
4912 #. type: Plain text
4913 #: doc/rust.md:2603
4914 msgid "The machine types are the following:"
4915 msgstr ""
4916
4917 #. type: Bullet: '* '
4918 #: doc/rust.md:2608
4919 msgid ""
4920 "The unsigned word types `u8`, `u16`, `u32` and `u64`, with values drawn from "
4921 "the integer intervals $[0, 2^8 - 1]$, $[0, 2^{16} - 1]$, $[0, 2^{32} - 1]$ "
4922 "and $[0, 2^{64} - 1]$ respectively."
4923 msgstr ""
4924
4925 #. type: Bullet: '* '
4926 #: doc/rust.md:2613
4927 msgid ""
4928 "The signed two's complement word types `i8`, `i16`, `i32` and `i64`, with "
4929 "values drawn from the integer intervals $[-(2^7), 2^7 - 1]$, $[-(2^{15}), "
4930 "2^{15} - 1]$, $[-(2^{31}), 2^{31} - 1]$, $[-(2^{63}), 2^{63} - 1]$ "
4931 "respectively."
4932 msgstr ""
4933
4934 #. type: Bullet: '* '
4935 #: doc/rust.md:2616
4936 msgid ""
4937 "The IEEE 754-2008 `binary32` and `binary64` floating-point types: `f32` and "
4938 "`f64`, respectively."
4939 msgstr ""
4940
4941 #. type: Plain text
4942 #: doc/rust.md:2618
4943 msgid "#### Machine-dependent integer types"
4944 msgstr ""
4945
4946 #. type: Plain text
4947 #: doc/rust.md:2623
4948 msgid ""
4949 "The Rust type `uint`^[A Rust `uint` is analogous to a C99 `uintptr_t`.] is "
4950 "an unsigned integer type with target-machine-dependent size. Its size, in "
4951 "bits, is equal to the number of bits required to hold any memory address on "
4952 "the target machine."
4953 msgstr ""
4954
4955 #. type: Plain text
4956 #: doc/rust.md:2628
4957 msgid ""
4958 "The Rust type `int`^[A Rust `int` is analogous to a C99 `intptr_t`.] is a "
4959 "two's complement signed integer type with target-machine-dependent size. Its "
4960 "size, in bits, is equal to the size of the rust type `uint` on the same "
4961 "target machine."
4962 msgstr ""
4963
4964 #. type: Plain text
4965 #: doc/rust.md:2631
4966 msgid "#### Machine-dependent floating point type"
4967 msgstr ""
4968
4969 #. type: Plain text
4970 #: doc/rust.md:2638
4971 msgid ""
4972 "The Rust type `float` is a machine-specific type equal to one of the "
4973 "supported Rust floating-point machine types (`f32` or `f64`). It is the "
4974 "largest floating-point type that is directly supported by hardware on the "
4975 "target machine, or if the target machine has no floating-point hardware "
4976 "support, the largest floating-point type supported by the software floating-"
4977 "point library used to support the other floating-point machine types."
4978 msgstr ""
4979
4980 #. type: Plain text
4981 #: doc/rust.md:2641
4982 msgid ""
4983 "Note that due to the preference for hardware-supported floating-point, the "
4984 "type `float` may not be equal to the largest *supported* floating-point type."
4985 msgstr ""
4986
4987 #. type: Plain text
4988 #: doc/rust.md:2644
4989 msgid "### Textual types"
4990 msgstr ""
4991
4992 #. type: Plain text
4993 #: doc/rust.md:2646
4994 msgid "The types `char` and `str` hold textual data."
4995 msgstr ""
4996
4997 #. type: Plain text
4998 #: doc/rust.md:2649
4999 msgid ""
5000 "A value of type `char` is a Unicode character, represented as a 32-bit "
5001 "unsigned word holding a UCS-4 codepoint."
5002 msgstr ""
5003
5004 #. type: Plain text
5005 #: doc/rust.md:2655
5006 msgid ""
5007 "A value of type `str` is a Unicode string, represented as a vector of 8-bit "
5008 "unsigned bytes holding a sequence of UTF-8 codepoints.  Since `str` is of "
5009 "unknown size, it is not a _first class_ type, but can only be instantiated "
5010 "through a pointer type, such as `&str`, `@str` or `~str`."
5011 msgstr ""
5012
5013 #. type: Plain text
5014 #: doc/rust.md:2658
5015 msgid "### Tuple types"
5016 msgstr ""
5017
5018 #. type: Plain text
5019 #: doc/rust.md:2661
5020 msgid ""
5021 "The tuple type-constructor forms a new heterogeneous product of values "
5022 "similar to the record type-constructor. The differences are as follows:"
5023 msgstr ""
5024
5025 #. type: Bullet: '* '
5026 #: doc/rust.md:2664
5027 msgid "tuple elements cannot be mutable, unlike record fields"
5028 msgstr ""
5029
5030 #. type: Bullet: '* '
5031 #: doc/rust.md:2664
5032 msgid ""
5033 "tuple elements are not named and can be accessed only by pattern-matching"
5034 msgstr ""
5035
5036 #. type: Plain text
5037 #: doc/rust.md:2668
5038 msgid ""
5039 "Tuple types and values are denoted by listing the types or values of their "
5040 "elements, respectively, in a parenthesized, comma-separated list."
5041 msgstr ""
5042
5043 #. type: Plain text
5044 #: doc/rust.md:2671
5045 msgid ""
5046 "The members of a tuple are laid out in memory contiguously, like a record, "
5047 "in order specified by the tuple type."
5048 msgstr ""
5049
5050 #. type: Plain text
5051 #: doc/rust.md:2673
5052 msgid "An example of a tuple type and its use:"
5053 msgstr ""
5054
5055 #. type: Plain text
5056 #: doc/rust.md:2680
5057 msgid ""
5058 "~~~~ type Pair<'self> = (int,&'self str); let p: Pair<'static> = (10,\"hello"
5059 "\"); let (a, b) = p; assert!(b != \"world\"); ~~~~"
5060 msgstr ""
5061
5062 #. type: Plain text
5063 #: doc/rust.md:2683
5064 msgid "### Vector types"
5065 msgstr ""
5066
5067 #. type: Plain text
5068 #: doc/rust.md:2696
5069 msgid ""
5070 "The vector type constructor represents a homogeneous array of values of a "
5071 "given type.  A vector has a fixed size.  (Operations like `vec.push` operate "
5072 "solely on owned vectors.)  A vector type can be annotated with a _definite_ "
5073 "size, written with a trailing asterisk and integer literal, such as `[int * "
5074 "10]`.  Such a definite-sized vector type is a first-class type, since its "
5075 "size is known statically.  A vector without such a size is said to be of "
5076 "_indefinite_ size, and is therefore not a _first-class_ type.  An indefinite-"
5077 "size vector can only be instantiated through a pointer type, such as `&[T]`, "
5078 "`@[T]` or `~[T]`.  The kind of a vector type depends on the kind of its "
5079 "element type, as with other simple structural types."
5080 msgstr ""
5081
5082 #. type: Plain text
5083 #: doc/rust.md:2700
5084 msgid ""
5085 "Expressions producing vectors of definite size cannot be evaluated in a "
5086 "context expecting a vector of indefinite size; one must copy the definite-"
5087 "sized vector contents into a distinct vector of indefinite size."
5088 msgstr ""
5089
5090 #. type: Plain text
5091 #: doc/rust.md:2702
5092 msgid "An example of a vector type and its use:"
5093 msgstr ""
5094
5095 #. type: Plain text
5096 #: doc/rust.md:2708
5097 msgid ""
5098 "~~~~ let v: &[int] = &[7, 5, 3]; let i: int = v[2]; assert!(i == 3); ~~~~"
5099 msgstr ""
5100
5101 #. type: Plain text
5102 #: doc/rust.md:2711
5103 msgid ""
5104 "All in-bounds elements of a vector are always initialized, and access to a "
5105 "vector is always bounds-checked."
5106 msgstr ""
5107
5108 #. type: Plain text
5109 #: doc/rust.md:2714
5110 msgid "### Structure types"
5111 msgstr ""
5112
5113 #. type: Plain text
5114 #: doc/rust.md:2719
5115 msgid ""
5116 "A `struct` *type* is a heterogeneous product of other types, called the "
5117 "*fields* of the type.  ^[`struct` types are analogous `struct` types in C, "
5118 "the *record* types of the ML family, or the *structure* types of the Lisp "
5119 "family.]"
5120 msgstr ""
5121
5122 #. type: Plain text
5123 #: doc/rust.md:2721
5124 msgid ""
5125 "New instances of a `struct` can be constructed with a [struct expression]"
5126 "(#struct-expressions)."
5127 msgstr ""
5128
5129 #. type: Plain text
5130 #: doc/rust.md:2725
5131 msgid ""
5132 "The memory order of fields in a `struct` is given by the item defining it.  "
5133 "Fields may be given in any order in a corresponding struct *expression*; the "
5134 "resulting `struct` value will always be laid out in memory in the order "
5135 "specified by the corresponding *item*."
5136 msgstr ""
5137
5138 #. type: Plain text
5139 #: doc/rust.md:2728
5140 msgid ""
5141 "The fields of a `struct` may be qualified by [visibility modifiers]"
5142 "(#visibility-modifiers), to restrict access to implementation-private data "
5143 "in a structure."
5144 msgstr ""
5145
5146 #. type: Plain text
5147 #: doc/rust.md:2730
5148 msgid ""
5149 "A _tuple struct_ type is just like a structure type, except that the fields "
5150 "are anonymous."
5151 msgstr ""
5152
5153 #. type: Plain text
5154 #: doc/rust.md:2733
5155 msgid ""
5156 "A _unit-like struct_ type is like a structure type, except that it has no "
5157 "fields.  The one value constructed by the associated [structure expression]"
5158 "(#structure-expression) is the only value that inhabits such a type."
5159 msgstr ""
5160
5161 #. type: Plain text
5162 #: doc/rust.md:2735
5163 msgid "### Enumerated types"
5164 msgstr ""
5165
5166 #. type: Plain text
5167 #: doc/rust.md:2740
5168 msgid ""
5169 "An *enumerated type* is a nominal, heterogeneous disjoint union type, "
5170 "denoted by the name of an [`enum` item](#enumerations).  ^[The `enum` type "
5171 "is analogous to a `data` constructor declaration in ML, or a *pick ADT* in "
5172 "Limbo.]"
5173 msgstr ""
5174
5175 #. type: Plain text
5176 #: doc/rust.md:2743
5177 msgid ""
5178 "An [`enum` item](#enumerations) declares both the type and a number of "
5179 "*variant constructors*, each of which is independently named and takes an "
5180 "optional tuple of arguments."
5181 msgstr ""
5182
5183 #. type: Plain text
5184 #: doc/rust.md:2746
5185 msgid ""
5186 "New instances of an `enum` can be constructed by calling one of the variant "
5187 "constructors, in a [call expression](#call-expressions)."
5188 msgstr ""
5189
5190 #. type: Plain text
5191 #: doc/rust.md:2748
5192 msgid ""
5193 "Any `enum` value consumes as much memory as the largest variant constructor "
5194 "for its corresponding `enum` type."
5195 msgstr ""
5196
5197 #. type: Plain text
5198 #: doc/rust.md:2751
5199 msgid ""
5200 "Enum types cannot be denoted *structurally* as types, but must be denoted by "
5201 "named reference to an [`enum` item](#enumerations)."
5202 msgstr ""
5203
5204 #. type: Plain text
5205 #: doc/rust.md:2754
5206 msgid "### Recursive types"
5207 msgstr ""
5208
5209 #. type: Plain text
5210 #: doc/rust.md:2758
5211 msgid ""
5212 "Nominal types -- [enumerations](#enumerated-types) and [structures]"
5213 "(#structure-types) -- may be recursive.  That is, each `enum` constructor or "
5214 "`struct` field may refer, directly or indirectly, to the enclosing `enum` or "
5215 "`struct` type itself.  Such recursion has restrictions:"
5216 msgstr ""
5217
5218 #. type: Plain text
5219 #: doc/rust.md:2768
5220 #, no-wrap
5221 msgid ""
5222 "* Recursive types must include a nominal type in the recursion\n"
5223 "  (not mere [type definitions](#type-definitions),\n"
5224 "   or other structural types such as [vectors](#vector-types) or [tuples](#tuple-types)).\n"
5225 "* A recursive `enum` item must have at least one non-recursive constructor\n"
5226 "  (in order to give the recursion a basis case).\n"
5227 "* The size of a recursive type must be finite;\n"
5228 "  in other words the recursive fields of the type must be [pointer types](#pointer-types).\n"
5229 "* Recursive type definitions can cross module boundaries, but not module *visibility* boundaries,\n"
5230 "  or crate boundaries (in order to simplify the module system and type checker).\n"
5231 msgstr ""
5232
5233 #. type: Plain text
5234 #: doc/rust.md:2770
5235 msgid "An example of a *recursive* type and its use:"
5236 msgstr ""
5237
5238 #. type: Plain text
5239 #: doc/rust.md:2776
5240 #, no-wrap
5241 msgid ""
5242 "~~~~\n"
5243 "enum List<T> {\n"
5244 "  Nil,\n"
5245 "  Cons(T, @List<T>)\n"
5246 "}\n"
5247 msgstr ""
5248
5249 #. type: Plain text
5250 #: doc/rust.md:2779
5251 msgid "let a: List<int> = Cons(7, @Cons(13, @Nil)); ~~~~"
5252 msgstr ""
5253
5254 #. type: Plain text
5255 #: doc/rust.md:2782
5256 msgid "### Pointer types"
5257 msgstr ""
5258
5259 #. type: Plain text
5260 #: doc/rust.md:2786
5261 msgid ""
5262 "All pointers in Rust are explicit first-class values.  They can be copied, "
5263 "stored into data structures, and returned from functions.  There are four "
5264 "varieties of pointer in Rust:"
5265 msgstr ""
5266
5267 #. type: Plain text
5268 #: doc/rust.md:2796
5269 #, no-wrap
5270 msgid ""
5271 "Managed pointers (`@`)\n"
5272 "  : These point to managed heap allocations (or \"boxes\") in the task-local, managed heap.\n"
5273 "    Managed pointers are written `@content`,\n"
5274 "    for example `@int` means a managed pointer to a managed box containing an integer.\n"
5275 "    Copying a managed pointer is a \"shallow\" operation:\n"
5276 "    it involves only copying the pointer itself\n"
5277 "    (as well as any reference-count or GC-barriers required by the managed heap).\n"
5278 "    Dropping a managed pointer does not necessarily release the box it points to;\n"
5279 "    the lifecycles of managed boxes are subject to an unspecified garbage collection algorithm.\n"
5280 msgstr ""
5281
5282 #. type: Plain text
5283 #: doc/rust.md:2805
5284 #, no-wrap
5285 msgid ""
5286 "Owning pointers (`~`)\n"
5287 "  : These point to owned heap allocations (or \"boxes\") in the shared, inter-task heap.\n"
5288 "    Each owned box has a single owning pointer; pointer and pointee retain a 1:1 relationship at all times.\n"
5289 "    Owning pointers are written `~content`,\n"
5290 "    for example `~int` means an owning pointer to an owned box containing an integer.\n"
5291 "    Copying an owned box is a \"deep\" operation:\n"
5292 "    it involves allocating a new owned box and copying the contents of the old box into the new box.\n"
5293 "    Releasing an owning pointer immediately releases its corresponding owned box.\n"
5294 msgstr ""
5295
5296 #. type: Plain text
5297 #: doc/rust.md:2818
5298 #, no-wrap
5299 msgid ""
5300 "Borrowed pointers (`&`)\n"
5301 "  : These point to memory _owned by some other value_.\n"
5302 "    Borrowed pointers arise by (automatic) conversion from owning pointers, managed pointers,\n"
5303 "    or by applying the borrowing operator `&` to some other value,\n"
5304 "    including [lvalues, rvalues or temporaries](#lvalues-rvalues-and-temporaries).\n"
5305 "    Borrowed pointers are written `&content`, or in some cases `&f/content` for some lifetime-variable `f`,\n"
5306 "    for example `&int` means a borrowed pointer to an integer.\n"
5307 "    Copying a borrowed pointer is a \"shallow\" operation:\n"
5308 "    it involves only copying the pointer itself.\n"
5309 "    Releasing a borrowed pointer typically has no effect on the value it points to,\n"
5310 "    with the exception of temporary values,\n"
5311 "    which are released when the last borrowed pointer to them is released.\n"
5312 msgstr ""
5313
5314 #. type: Plain text
5315 #: doc/rust.md:2828
5316 #, no-wrap
5317 msgid ""
5318 "Raw pointers (`*`)\n"
5319 "  : Raw pointers are pointers without safety or liveness guarantees.\n"
5320 "    Raw pointers are written `*content`,\n"
5321 "    for example `*int` means a raw pointer to an integer.\n"
5322 "    Copying or dropping a raw pointer is has no effect on the lifecycle of any other value.\n"
5323 "    Dereferencing a raw pointer or converting it to any other pointer type is an [`unsafe` operation](#unsafe-functions).\n"
5324 "    Raw pointers are generally discouraged in Rust code;\n"
5325 "    they exist to support interoperability with foreign code,\n"
5326 "    and writing performance-critical or low-level functions.\n"
5327 msgstr ""
5328
5329 #. type: Plain text
5330 #: doc/rust.md:2831
5331 msgid "### Function types"
5332 msgstr ""
5333
5334 #. type: Plain text
5335 #: doc/rust.md:2835
5336 msgid ""
5337 "The function type constructor `fn` forms new function types.  A function "
5338 "type consists of a possibly-empty set of function-type modifiers (such as "
5339 "`unsafe` or `extern`), a sequence of input types and an output type."
5340 msgstr ""
5341
5342 #. type: Plain text
5343 #: doc/rust.md:2837
5344 msgid "An example of a `fn` type:"
5345 msgstr ""
5346
5347 #. type: Plain text
5348 #: doc/rust.md:2842
5349 #, no-wrap
5350 msgid ""
5351 "~~~~~~~~\n"
5352 "fn add(x: int, y: int) -> int {\n"
5353 "  return x + y;\n"
5354 "}\n"
5355 msgstr ""
5356
5357 #. type: Plain text
5358 #: doc/rust.md:2844
5359 msgid "let mut x = add(5,7);"
5360 msgstr ""
5361
5362 #. type: Plain text
5363 #: doc/rust.md:2849
5364 msgid ""
5365 "type Binop<'self> = &'self fn(int,int) -> int; let bo: Binop = add; x = "
5366 "bo(5,7); ~~~~~~~~"
5367 msgstr ""
5368
5369 #. type: Plain text
5370 #: doc/rust.md:2851
5371 msgid "### Object types"
5372 msgstr ""
5373
5374 #. type: Plain text
5375 #: doc/rust.md:2858
5376 msgid ""
5377 "Every trait item (see [traits](#traits)) defines a type with the same name "
5378 "as the trait.  This type is called the _object type_ of the trait.  Object "
5379 "types permit \"late binding\" of methods, dispatched using _virtual method "
5380 "tables_ (\"vtables\").  Whereas most calls to trait methods are \"early bound"
5381 "\" (statically resolved) to specific implementations at compile time, a call "
5382 "to a method on an object type is only resolved to a vtable entry at compile "
5383 "time.  The actual implementation for each vtable entry can vary on an object-"
5384 "by-object basis."
5385 msgstr ""
5386
5387 #. type: Plain text
5388 #: doc/rust.md:2863
5389 msgid ""
5390 "Given a pointer-typed expression `E` of type `&T`, `~T` or `@T`, where `T` "
5391 "implements trait `R`, casting `E` to the corresponding pointer type `&R`, "
5392 "`~R` or `@R` results in a value of the _object type_ `R`.  This result is "
5393 "represented as a pair of pointers: the vtable pointer for the `T` "
5394 "implementation of `R`, and the pointer value of `E`."
5395 msgstr ""
5396
5397 #. type: Plain text
5398 #: doc/rust.md:2865
5399 msgid "An example of an object type:"
5400 msgstr ""
5401
5402 #. type: Plain text
5403 #: doc/rust.md:2871
5404 #, no-wrap
5405 msgid ""
5406 "~~~~~~~~\n"
5407 "# use std::int;\n"
5408 "trait Printable {\n"
5409 "  fn to_str(&self) -> ~str;\n"
5410 "}\n"
5411 msgstr ""
5412
5413 #. type: Plain text
5414 #: doc/rust.md:2875
5415 #, no-wrap
5416 msgid ""
5417 "impl Printable for int {\n"
5418 "  fn to_str(&self) -> ~str { int::to_str(*self) }\n"
5419 "}\n"
5420 msgstr ""
5421
5422 #. type: Plain text
5423 #: doc/rust.md:2879
5424 #, no-wrap
5425 msgid ""
5426 "fn print(a: @Printable) {\n"
5427 "   println(a.to_str());\n"
5428 "}\n"
5429 msgstr ""
5430
5431 #. type: Plain text
5432 #: doc/rust.md:2884
5433 #, no-wrap
5434 msgid ""
5435 "fn main() {\n"
5436 "   print(@10 as @Printable);\n"
5437 "}\n"
5438 "~~~~~~~~\n"
5439 msgstr ""
5440
5441 #. type: Plain text
5442 #: doc/rust.md:2887
5443 msgid ""
5444 "In this example, the trait `Printable` occurs as an object type in both the "
5445 "type signature of `print`, and the cast expression in `main`."
5446 msgstr ""
5447
5448 #. type: Plain text
5449 #: doc/rust.md:2889
5450 msgid "### Type parameters"
5451 msgstr ""
5452
5453 #. type: Plain text
5454 #: doc/rust.md:2891
5455 msgid ""
5456 "Within the body of an item that has type parameter declarations, the names "
5457 "of its type parameters are types:"
5458 msgstr ""
5459
5460 #. type: Plain text
5461 #: doc/rust.md:2902
5462 #, no-wrap
5463 msgid ""
5464 "~~~~~~~\n"
5465 "fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {\n"
5466 "    if xs.len() == 0 {\n"
5467 "       return ~[];\n"
5468 "    }\n"
5469 "    let first: B = f(xs[0].clone());\n"
5470 "    let rest: ~[B] = map(f, xs.slice(1, xs.len()));\n"
5471 "    return ~[first] + rest;\n"
5472 "}\n"
5473 "~~~~~~~\n"
5474 msgstr ""
5475
5476 #. type: Plain text
5477 #: doc/rust.md:2905
5478 msgid ""
5479 "Here, `first` has type `B`, referring to `map`'s `B` type parameter; and "
5480 "`rest` has type `~[B]`, a vector type with element type `B`."
5481 msgstr ""
5482
5483 #. type: Plain text
5484 #: doc/rust.md:2907
5485 msgid "### Self types"
5486 msgstr ""
5487
5488 #. type: Plain text
5489 #: doc/rust.md:2911
5490 msgid ""
5491 "The special type `self` has a meaning within methods inside an impl item. It "
5492 "refers to the type of the implicit `self` argument. For example, in:"
5493 msgstr ""
5494
5495 #. type: Plain text
5496 #: doc/rust.md:2916
5497 #, no-wrap
5498 msgid ""
5499 "~~~~~~~~\n"
5500 "trait Printable {\n"
5501 "  fn make_string(&self) -> ~str;\n"
5502 "}\n"
5503 msgstr ""
5504
5505 #. type: Plain text
5506 #: doc/rust.md:2923
5507 #, no-wrap
5508 msgid ""
5509 "impl Printable for ~str {\n"
5510 "    fn make_string(&self) -> ~str {\n"
5511 "        (*self).clone()\n"
5512 "    }\n"
5513 "}\n"
5514 "~~~~~~~~\n"
5515 msgstr ""
5516
5517 #. type: Plain text
5518 #: doc/rust.md:2926
5519 msgid ""
5520 "`self` refers to the value of type `~str` that is the receiver for a call to "
5521 "the method `make_string`."
5522 msgstr ""
5523
5524 #. type: Plain text
5525 #: doc/rust.md:2928
5526 msgid "## Type kinds"
5527 msgstr ""
5528
5529 #. type: Plain text
5530 #: doc/rust.md:2931
5531 msgid ""
5532 "Types in Rust are categorized into kinds, based on various properties of the "
5533 "components of the type.  The kinds are:"
5534 msgstr ""
5535
5536 #. type: Plain text
5537 #: doc/rust.md:2957
5538 #, no-wrap
5539 msgid ""
5540 "`Freeze`\n"
5541 "  : Types of this kind are deeply immutable;\n"
5542 "    they contain no mutable memory locations\n"
5543 "    directly or indirectly via pointers.\n"
5544 "`Send`\n"
5545 "  : Types of this kind can be safely sent between tasks.\n"
5546 "    This kind includes scalars, owning pointers, owned closures, and\n"
5547 "    structural types containing only other owned types.\n"
5548 "    All `Send` types are `'static`.\n"
5549 "`'static`\n"
5550 "  : Types of this kind do not contain any borrowed pointers;\n"
5551 "    this can be a useful guarantee for code\n"
5552 "    that breaks borrowing assumptions\n"
5553 "    using [`unsafe` operations](#unsafe-functions).\n"
5554 "`Drop`\n"
5555 "  : This is not strictly a kind,\n"
5556 "    but its presence interacts with kinds:\n"
5557 "    the `Drop` trait provides a single method `drop`\n"
5558 "    that takes no parameters,\n"
5559 "    and is run when values of the type are dropped.\n"
5560 "    Such a method is called a \"destructor\",\n"
5561 "    and are always executed in \"top-down\" order:\n"
5562 "    a value is completely destroyed\n"
5563 "    before any of the values it owns run their destructors.\n"
5564 "    Only `Send` types can implement `Drop`.\n"
5565 msgstr ""
5566
5567 #. type: Plain text
5568 #: doc/rust.md:2964
5569 #, no-wrap
5570 msgid ""
5571 "_Default_\n"
5572 "  : Types with destructors, closure environments,\n"
5573 "    and various other _non-first-class_ types,\n"
5574 "    are not copyable at all.\n"
5575 "    Such types can usually only be accessed through pointers,\n"
5576 "    or in some cases, moved between mutable locations.\n"
5577 msgstr ""
5578
5579 #. type: Plain text
5580 #: doc/rust.md:2967
5581 msgid ""
5582 "Kinds can be supplied as _bounds_ on type parameters, like traits, in which "
5583 "case the parameter is constrained to types satisfying that kind."
5584 msgstr ""
5585
5586 #. type: Plain text
5587 #: doc/rust.md:2973
5588 msgid ""
5589 "By default, type parameters do not carry any assumed kind-bounds at all.  "
5590 "When instantiating a type parameter, the kind bounds on the parameter are "
5591 "checked to be the same or narrower than the kind of the type that it is "
5592 "instantiated with."
5593 msgstr ""
5594
5595 #. type: Plain text
5596 #: doc/rust.md:2978
5597 msgid ""
5598 "Sending operations are not part of the Rust language, but are implemented in "
5599 "the library.  Generic functions that send values bound the kind of these "
5600 "values to sendable."
5601 msgstr ""
5602
5603 #. type: Plain text
5604 #: doc/rust.md:2980
5605 msgid "# Memory and concurrency models"
5606 msgstr ""
5607
5608 #. type: Plain text
5609 #: doc/rust.md:2985
5610 msgid ""
5611 "Rust has a memory model centered around concurrently-executing _tasks_. Thus "
5612 "its memory model and its concurrency model are best discussed "
5613 "simultaneously, as parts of each only make sense when considered from the "
5614 "perspective of the other."
5615 msgstr ""
5616
5617 #. type: Plain text
5618 #: doc/rust.md:2990
5619 msgid ""
5620 "When reading about the memory model, keep in mind that it is partitioned in "
5621 "order to support tasks; and when reading about tasks, keep in mind that "
5622 "their isolation and communication mechanisms are only possible due to the "
5623 "ownership and lifetime semantics of the memory model."
5624 msgstr ""
5625
5626 #. type: Plain text
5627 #: doc/rust.md:2992
5628 msgid "## Memory model"
5629 msgstr ""
5630
5631 #. type: Plain text
5632 #: doc/rust.md:2996
5633 msgid ""
5634 "A Rust program's memory consists of a static set of *items*, a set of [tasks]"
5635 "(#tasks) each with its own *stack*, and a *heap*. Immutable portions of the "
5636 "heap may be shared between tasks, mutable portions may not."
5637 msgstr ""
5638
5639 #. type: Plain text
5640 #: doc/rust.md:2999
5641 msgid ""
5642 "Allocations in the stack consist of *slots*, and allocations in the heap "
5643 "consist of *boxes*."
5644 msgstr ""
5645
5646 #. type: Plain text
5647 #: doc/rust.md:3002
5648 msgid "### Memory allocation and lifetime"
5649 msgstr ""
5650
5651 #. type: Plain text
5652 #: doc/rust.md:3007
5653 msgid ""
5654 "The _items_ of a program are those functions, modules and types that have "
5655 "their value calculated at compile-time and stored uniquely in the memory "
5656 "image of the rust process. Items are neither dynamically allocated nor freed."
5657 msgstr ""
5658
5659 #. type: Plain text
5660 #: doc/rust.md:3011
5661 msgid ""
5662 "A task's _stack_ consists of activation frames automatically allocated on "
5663 "entry to each function as the task executes. A stack allocation is reclaimed "
5664 "when control leaves the frame containing it."
5665 msgstr ""
5666
5667 #. type: Plain text
5668 #: doc/rust.md:3018
5669 msgid ""
5670 "The _heap_ is a general term that describes two separate sets of boxes: "
5671 "managed boxes -- which may be subject to garbage collection -- and owned "
5672 "boxes.  The lifetime of an allocation in the heap depends on the lifetime of "
5673 "the box values pointing to it. Since box values may themselves be passed in "
5674 "and out of frames, or stored in the heap, heap allocations may outlive the "
5675 "frame they are allocated within."
5676 msgstr ""
5677
5678 #. type: Plain text
5679 #: doc/rust.md:3020
5680 msgid "### Memory ownership"
5681 msgstr ""
5682
5683 #. type: Plain text
5684 #: doc/rust.md:3023
5685 msgid ""
5686 "A task owns all memory it can *safely* reach through local variables, as "
5687 "well as managed, owning and borrowed pointers."
5688 msgstr ""
5689
5690 #. type: Plain text
5691 #: doc/rust.md:3030
5692 msgid ""
5693 "When a task sends a value that has the `Send` trait to another task, it "
5694 "loses ownership of the value sent and can no longer refer to it.  This is "
5695 "statically guaranteed by the combined use of \"move semantics\", and the "
5696 "compiler-checked _meaning_ of the `Send` trait: it is only instantiated for "
5697 "(transitively) sendable kinds of data constructor and pointers, never "
5698 "including managed or borrowed pointers."
5699 msgstr ""
5700
5701 #. type: Plain text
5702 #: doc/rust.md:3033
5703 msgid ""
5704 "When a stack frame is exited, its local allocations are all released, and "
5705 "its references to boxes (both managed and owned) are dropped."
5706 msgstr ""
5707
5708 #. type: Plain text
5709 #: doc/rust.md:3039
5710 msgid ""
5711 "A managed box may (in the case of a recursive, mutable managed type) be "
5712 "cyclic; in this case the release of memory inside the managed structure may "
5713 "be deferred until task-local garbage collection can reclaim it. Code can "
5714 "ensure no such delayed deallocation occurs by restricting itself to owned "
5715 "boxes and similar unmanaged kinds of data."
5716 msgstr ""
5717
5718 #. type: Plain text
5719 #: doc/rust.md:3042
5720 msgid ""
5721 "When a task finishes, its stack is necessarily empty and it therefore has no "
5722 "references to any boxes; the remainder of its heap is immediately freed."
5723 msgstr ""
5724
5725 #. type: Plain text
5726 #: doc/rust.md:3045
5727 msgid "### Memory slots"
5728 msgstr ""
5729
5730 #. type: Plain text
5731 #: doc/rust.md:3047
5732 msgid "A task's stack contains slots."
5733 msgstr ""
5734
5735 #. type: Plain text
5736 #: doc/rust.md:3050
5737 msgid ""
5738 "A _slot_ is a component of a stack frame, either a function parameter, a "
5739 "[temporary](#lvalues-rvalues-and-temporaries), or a local variable."
5740 msgstr ""
5741
5742 #. type: Plain text
5743 #: doc/rust.md:3053
5744 msgid ""
5745 "A _local variable_ (or *stack-local* allocation) holds a value directly, "
5746 "allocated within the stack's memory. The value is a part of the stack frame."
5747 msgstr ""
5748
5749 #. type: Plain text
5750 #: doc/rust.md:3058
5751 msgid ""
5752 "Local variables are immutable unless declared with `let mut`.  The `mut` "
5753 "keyword applies to all local variables declared within that declaration (so "
5754 "`let mut (x, y) = ...` declares two mutable variables, `x` and `y`)."
5755 msgstr ""
5756
5757 #. type: Plain text
5758 #: doc/rust.md:3063
5759 msgid ""
5760 "Function parameters are immutable unless declared with `mut`. The `mut` "
5761 "keyword applies only to the following parameter (so `|mut x, y|` and `fn "
5762 "f(mut x: ~int, y: ~int)` declare one mutable variable `x` and one immutable "
5763 "variable `y`)."
5764 msgstr ""
5765
5766 #. type: Plain text
5767 #: doc/rust.md:3069
5768 msgid ""
5769 "Local variables are not initialized when allocated; the entire frame worth "
5770 "of local variables are allocated at once, on frame-entry, in an "
5771 "uninitialized state. Subsequent statements within a function may or may not "
5772 "initialize the local variables. Local variables can be used only after they "
5773 "have been initialized; this is enforced by the compiler."
5774 msgstr ""
5775
5776 #. type: Plain text
5777 #: doc/rust.md:3072
5778 msgid "### Memory boxes"
5779 msgstr ""
5780
5781 #. type: Plain text
5782 #: doc/rust.md:3075
5783 msgid ""
5784 "A _box_ is a reference to a heap allocation holding another value. There are "
5785 "two kinds of boxes: *managed boxes* and *owned boxes*."
5786 msgstr ""
5787
5788 #. type: Plain text
5789 #: doc/rust.md:3077
5790 msgid ""
5791 "A _managed box_ type or value is constructed by the prefix *at* sigil `@`."
5792 msgstr ""
5793
5794 #. type: Plain text
5795 #: doc/rust.md:3079
5796 msgid ""
5797 "An _owned box_ type or value is constructed by the prefix *tilde* sigil `~`."
5798 msgstr ""
5799
5800 #. type: Plain text
5801 #: doc/rust.md:3084
5802 msgid ""
5803 "Multiple managed box values can point to the same heap allocation; copying a "
5804 "managed box value makes a shallow copy of the pointer (optionally "
5805 "incrementing a reference count, if the managed box is implemented through "
5806 "reference-counting)."
5807 msgstr ""
5808
5809 #. type: Plain text
5810 #: doc/rust.md:3086
5811 msgid ""
5812 "Owned box values exist in 1:1 correspondence with their heap allocation."
5813 msgstr ""
5814
5815 #. type: Plain text
5816 #: doc/rust.md:3089
5817 msgid ""
5818 "An example of constructing one managed box type and value, and one owned box "
5819 "type and value:"
5820 msgstr ""
5821
5822 #. type: Plain text
5823 #: doc/rust.md:3094
5824 msgid "~~~~~~~~ let x: @int = @10; let x: ~int = ~10; ~~~~~~~~"
5825 msgstr ""
5826
5827 #. type: Plain text
5828 #: doc/rust.md:3097
5829 msgid ""
5830 "Some operations (such as field selection) implicitly dereference boxes. An "
5831 "example of an _implicit dereference_ operation performed on box values:"
5832 msgstr ""
5833
5834 #. type: Plain text
5835 #: doc/rust.md:3103
5836 msgid ""
5837 "~~~~~~~~ struct Foo { y: int } let x = @Foo{y: 10}; assert!(x.y == 10); "
5838 "~~~~~~~~"
5839 msgstr ""
5840
5841 #. type: Plain text
5842 #: doc/rust.md:3109
5843 msgid ""
5844 "Other operations act on box values as single-word-sized address values. For "
5845 "these operations, to access the value held in the box requires an explicit "
5846 "dereference of the box value. Explicitly dereferencing a box is indicated "
5847 "with the unary *star* operator `*`. Examples of such _explicit dereference_ "
5848 "operations are:"
5849 msgstr ""
5850
5851 #. type: Bullet: '* '
5852 #: doc/rust.md:3112
5853 msgid "copying box values (`x = y`)"
5854 msgstr ""
5855
5856 #. type: Bullet: '* '
5857 #: doc/rust.md:3112
5858 msgid "passing box values to functions (`f(x,y)`)"
5859 msgstr ""
5860
5861 #. type: Plain text
5862 #: doc/rust.md:3115
5863 msgid ""
5864 "An example of an explicit-dereference operation performed on box values:"
5865 msgstr ""
5866
5867 #. type: Plain text
5868 #: doc/rust.md:3119
5869 msgid "~~~~~~~~ fn takes_boxed(b: @int) { }"
5870 msgstr ""
5871
5872 #. type: Plain text
5873 #: doc/rust.md:3122
5874 msgid "fn takes_unboxed(b: int) { }"
5875 msgstr ""
5876
5877 #. type: Plain text
5878 #: doc/rust.md:3129
5879 #, no-wrap
5880 msgid ""
5881 "fn main() {\n"
5882 "    let x: @int = @10;\n"
5883 "    takes_boxed(x);\n"
5884 "    takes_unboxed(*x);\n"
5885 "}\n"
5886 "~~~~~~~~\n"
5887 msgstr ""
5888
5889 #. type: Plain text
5890 #: doc/rust.md:3131
5891 msgid "## Tasks"
5892 msgstr ""
5893
5894 #. type: Plain text
5895 #: doc/rust.md:3139
5896 msgid ""
5897 "An executing Rust program consists of a tree of tasks.  A Rust _task_ "
5898 "consists of an entry function, a stack, a set of outgoing communication "
5899 "channels and incoming communication ports, and ownership of some portion of "
5900 "the heap of a single operating-system process.  (We expect that many "
5901 "programs will not use channels and ports directly, but will instead use "
5902 "higher-level abstractions provided in standard libraries, such as pipes.)"
5903 msgstr ""
5904
5905 #. type: Plain text
5906 #: doc/rust.md:3154
5907 msgid ""
5908 "Multiple Rust tasks may coexist in a single operating-system process.  The "
5909 "runtime scheduler maps tasks to a certain number of operating-system "
5910 "threads.  By default, the scheduler chooses the number of threads based on "
5911 "the number of concurrent physical CPUs detected at startup.  It's also "
5912 "possible to override this choice at runtime.  When the number of tasks "
5913 "exceeds the number of threads -- which is likely -- the scheduler "
5914 "multiplexes the tasks onto threads.^[ This is an M:N scheduler, which is "
5915 "known to give suboptimal results for CPU-bound concurrency problems.  In "
5916 "such cases, running with the same number of threads and tasks can yield "
5917 "better results.  Rust has M:N scheduling in order to support very large "
5918 "numbers of tasks in contexts where threads are too resource-intensive to use "
5919 "in large number.  The cost of threads varies substantially per operating "
5920 "system, and is sometimes quite low, so this flexibility is not always worth "
5921 "exploiting.]"
5922 msgstr ""
5923
5924 #. type: Plain text
5925 #: doc/rust.md:3157
5926 msgid "### Communication between tasks"
5927 msgstr ""
5928
5929 #. type: Plain text
5930 #: doc/rust.md:3162
5931 msgid ""
5932 "Rust tasks are isolated and generally unable to interfere with one another's "
5933 "memory directly, except through [`unsafe` code](#unsafe-functions).  All "
5934 "contact between tasks is mediated by safe forms of ownership transfer, and "
5935 "data races on memory are prohibited by the type system."
5936 msgstr ""
5937
5938 #. type: Plain text
5939 #: doc/rust.md:3165
5940 msgid ""
5941 "Inter-task communication and co-ordination facilities are provided in the "
5942 "standard library.  These include:"
5943 msgstr ""
5944
5945 #. type: Bullet: '  - '
5946 #: doc/rust.md:3169
5947 msgid ""
5948 "synchronous and asynchronous communication channels with various "
5949 "communication topologies"
5950 msgstr ""
5951
5952 #. type: Bullet: '  - '
5953 #: doc/rust.md:3169
5954 msgid ""
5955 "read-only and read-write shared variables with various safe mutual exclusion "
5956 "patterns"
5957 msgstr ""
5958
5959 #. type: Bullet: '  - '
5960 #: doc/rust.md:3169
5961 msgid "simple locks and semaphores"
5962 msgstr ""
5963
5964 #. type: Plain text
5965 #: doc/rust.md:3174
5966 msgid ""
5967 "When such facilities carry values, the values are restricted to the [`Send` "
5968 "type-kind](#type-kinds).  Restricting communication interfaces to this kind "
5969 "ensures that no borrowed or managed pointers move between tasks.  Thus "
5970 "access to an entire data structure can be mediated through its owning \"root"
5971 "\" value; no further locking or copying is required to avoid data races "
5972 "within the substructure of such a value."
5973 msgstr ""
5974
5975 #. type: Plain text
5976 #: doc/rust.md:3177
5977 msgid "### Task lifecycle"
5978 msgstr ""
5979
5980 #. type: Plain text
5981 #: doc/rust.md:3180
5982 msgid ""
5983 "The _lifecycle_ of a task consists of a finite set of states and events that "
5984 "cause transitions between the states. The lifecycle states of a task are:"
5985 msgstr ""
5986
5987 #. type: Bullet: '* '
5988 #: doc/rust.md:3185
5989 msgid "running"
5990 msgstr ""
5991
5992 #. type: Bullet: '* '
5993 #: doc/rust.md:3185
5994 msgid "blocked"
5995 msgstr ""
5996
5997 #. type: Bullet: '* '
5998 #: doc/rust.md:3185
5999 msgid "failing"
6000 msgstr ""
6001
6002 #. type: Bullet: '* '
6003 #: doc/rust.md:3185
6004 msgid "dead"
6005 msgstr ""
6006
6007 #. type: Plain text
6008 #: doc/rust.md:3189
6009 msgid ""
6010 "A task begins its lifecycle -- once it has been spawned -- in the *running* "
6011 "state. In this state it executes the statements of its entry function, and "
6012 "any functions called by the entry function."
6013 msgstr ""
6014
6015 #. type: Plain text
6016 #: doc/rust.md:3195
6017 msgid ""
6018 "A task may transition from the *running* state to the *blocked* state any "
6019 "time it makes a blocking communication call. When the call can be completed "
6020 "-- when a message arrives at a sender, or a buffer opens to receive a "
6021 "message -- then the blocked task will unblock and transition back to "
6022 "*running*."
6023 msgstr ""
6024
6025 #. type: Plain text
6026 #: doc/rust.md:3214
6027 msgid ""
6028 "A task may transition to the *failing* state at any time, due being killed "
6029 "by some external event or internally, from the evaluation of a `fail!()` "
6030 "macro. Once *failing*, a task unwinds its stack and transitions to the "
6031 "*dead* state. Unwinding the stack of a task is done by the task itself, on "
6032 "its own control stack. If a value with a destructor is freed during "
6033 "unwinding, the code for the destructor is run, also on the task's control "
6034 "stack. Running the destructor code causes a temporary transition to a "
6035 "*running* state, and allows the destructor code to cause any subsequent "
6036 "state transitions.  The original task of unwinding and failing thereby may "
6037 "suspend temporarily, and may involve (recursive) unwinding of the stack of a "
6038 "failed destructor. Nonetheless, the outermost unwinding activity will "
6039 "continue until the stack is unwound and the task transitions to the *dead* "
6040 "state. There is no way to \"recover\" from task failure.  Once a task has "
6041 "temporarily suspended its unwinding in the *failing* state, failure "
6042 "occurring from within this destructor results in *hard* failure.  The "
6043 "unwinding procedure of hard failure frees resources but does not execute "
6044 "destructors.  The original (soft) failure is still resumed at the point "
6045 "where it was temporarily suspended."
6046 msgstr ""
6047
6048 #. type: Plain text
6049 #: doc/rust.md:3218
6050 msgid ""
6051 "A task in the *dead* state cannot transition to other states; it exists only "
6052 "to have its termination status inspected by other tasks, and/or to await "
6053 "reclamation when the last reference to it drops."
6054 msgstr ""
6055
6056 #. type: Plain text
6057 #: doc/rust.md:3221
6058 msgid "### Task scheduling"
6059 msgstr ""
6060
6061 #. type: Plain text
6062 #: doc/rust.md:3225
6063 msgid ""
6064 "The currently scheduled task is given a finite *time slice* in which to "
6065 "execute, after which it is *descheduled* at a loop-edge or similar "
6066 "preemption point, and another task within is scheduled, pseudo-randomly."
6067 msgstr ""
6068
6069 #. type: Plain text
6070 #: doc/rust.md:3229
6071 msgid ""
6072 "An executing task can yield control at any time, by making a library call to "
6073 "`std::task::yield`, which deschedules it immediately. Entering any other non-"
6074 "executing state (blocked, dead) similarly deschedules the task."
6075 msgstr ""
6076
6077 #. type: Plain text
6078 #: doc/rust.md:3232
6079 msgid "# Runtime services, linkage and debugging"
6080 msgstr ""
6081
6082 #. type: Plain text
6083 #: doc/rust.md:3239
6084 msgid ""
6085 "The Rust _runtime_ is a relatively compact collection of C++ and Rust code "
6086 "that provides fundamental services and datatypes to all Rust tasks at run-"
6087 "time. It is smaller and simpler than many modern language runtimes. It is "
6088 "tightly integrated into the language's execution model of memory, tasks, "
6089 "communication and logging."
6090 msgstr ""
6091
6092 #. type: Plain text
6093 #: doc/rust.md:3241
6094 msgid ""
6095 "> **Note:** The runtime library will merge with the `std` library in future "
6096 "versions of Rust."
6097 msgstr ""
6098
6099 #. type: Plain text
6100 #: doc/rust.md:3243
6101 msgid "### Memory allocation"
6102 msgstr ""
6103
6104 #. type: Plain text
6105 #: doc/rust.md:3249
6106 msgid ""
6107 "The runtime memory-management system is based on a _service-provider "
6108 "interface_, through which the runtime requests blocks of memory from its "
6109 "environment and releases them back to its environment when they are no "
6110 "longer needed.  The default implementation of the service-provider interface "
6111 "consists of the C runtime functions `malloc` and `free`."
6112 msgstr ""
6113
6114 #. type: Plain text
6115 #: doc/rust.md:3253
6116 msgid ""
6117 "The runtime memory-management system, in turn, supplies Rust tasks with "
6118 "facilities for allocating, extending and releasing stacks, as well as "
6119 "allocating and freeing heap data."
6120 msgstr ""
6121
6122 #. type: Plain text
6123 #: doc/rust.md:3255
6124 msgid "### Built in types"
6125 msgstr ""
6126
6127 #. type: Plain text
6128 #: doc/rust.md:3259
6129 msgid ""
6130 "The runtime provides C and Rust code to assist with various built-in types, "
6131 "such as vectors, strings, and the low level communication system (ports, "
6132 "channels, tasks)."
6133 msgstr ""
6134
6135 #. type: Plain text
6136 #: doc/rust.md:3262
6137 msgid ""
6138 "Support for other built-in types such as simple types, tuples, records, and "
6139 "enums is open-coded by the Rust compiler."
6140 msgstr ""
6141
6142 #. type: Plain text
6143 #: doc/rust.md:3266
6144 msgid "### Task scheduling and communication"
6145 msgstr ""
6146
6147 #. type: Plain text
6148 #: doc/rust.md:3272
6149 msgid ""
6150 "The runtime provides code to manage inter-task communication.  This includes "
6151 "the system of task-lifecycle state transitions depending on the contents of "
6152 "queues, as well as code to copy values between queues and their recipients "
6153 "and to serialize values for transmission over operating-system inter-process "
6154 "communication facilities."
6155 msgstr ""
6156
6157 #. type: Plain text
6158 #: doc/rust.md:3275
6159 msgid "### Logging system"
6160 msgstr ""
6161
6162 #. type: Plain text
6163 #: doc/rust.md:3279
6164 msgid ""
6165 "The runtime contains a system for directing [logging expressions](#log-"
6166 "expressions) to a logging console and/or internal logging buffers. Logging "
6167 "can be enabled per module."
6168 msgstr ""
6169
6170 #. type: Plain text
6171 #: doc/rust.md:3286
6172 msgid ""
6173 "Logging output is enabled by setting the `RUST_LOG` environment variable.  "
6174 "`RUST_LOG` accepts a logging specification made up of a comma-separated list "
6175 "of paths, with optional log levels. For each module containing log "
6176 "expressions, if `RUST_LOG` contains the path to that module or a parent of "
6177 "that module, then logs of the appropriate level will be output to the "
6178 "console."
6179 msgstr ""
6180
6181 #. type: Plain text
6182 #: doc/rust.md:3294
6183 msgid ""
6184 "The path to a module consists of the crate name, any parent modules, then "
6185 "the module itself, all separated by double colons (`::`).  The optional log "
6186 "level can be appended to the module path with an equals sign (`=`) followed "
6187 "by the log level, from 1 to 4, inclusive. Level 1 is the error level, 2 is "
6188 "warning, 3 info, and 4 debug. Any logs less than or equal to the specified "
6189 "level will be output. If not specified then log level 4 is assumed."
6190 msgstr ""
6191
6192 #. type: Plain text
6193 #: doc/rust.md:3300
6194 msgid ""
6195 "As an example, to see all the logs generated by the compiler, you would set "
6196 "`RUST_LOG` to `rustc`, which is the crate name (as specified in its `link` "
6197 "[attribute](#attributes)). To narrow down the logs to just crate resolution, "
6198 "you would set it to `rustc::metadata::creader`. To see just error logging "
6199 "use `rustc=0`."
6200 msgstr ""
6201
6202 #. type: Plain text
6203 #: doc/rust.md:3305
6204 msgid ""
6205 "Note that when compiling source files that don't specify a crate name the "
6206 "crate is given a default name that matches the source file, with the "
6207 "extension removed. In that case, to turn on logging for a program compiled "
6208 "from, e.g. `helloworld.rs`, `RUST_LOG` should be set to `helloworld`."
6209 msgstr ""
6210
6211 #. type: Plain text
6212 #: doc/rust.md:3309
6213 msgid ""
6214 "As a convenience, the logging spec can also be set to a special pseudo-"
6215 "crate, `::help`. In this case, when the application starts, the runtime will "
6216 "simply output a list of loaded modules containing log expressions, then exit."
6217 msgstr ""
6218
6219 #. type: Plain text
6220 #: doc/rust.md:3314
6221 msgid ""
6222 "The Rust runtime itself generates logging information. The runtime's logs "
6223 "are generated for a number of artificial modules in the `::rt` pseudo-crate, "
6224 "and can be enabled just like the logs for any standard module. The full list "
6225 "of runtime logging modules follows."
6226 msgstr ""
6227
6228 #. type: Bullet: '* '
6229 #: doc/rust.md:3328
6230 msgid "`::rt::mem` Memory management"
6231 msgstr ""
6232
6233 #. type: Bullet: '* '
6234 #: doc/rust.md:3328
6235 msgid "`::rt::comm` Messaging and task communication"
6236 msgstr ""
6237
6238 #. type: Bullet: '* '
6239 #: doc/rust.md:3328
6240 msgid "`::rt::task` Task management"
6241 msgstr ""
6242
6243 #. type: Bullet: '* '
6244 #: doc/rust.md:3328
6245 msgid "`::rt::dom` Task scheduling"
6246 msgstr ""
6247
6248 #. type: Bullet: '* '
6249 #: doc/rust.md:3328
6250 msgid "`::rt::trace` Unused"
6251 msgstr ""
6252
6253 #. type: Bullet: '* '
6254 #: doc/rust.md:3328
6255 msgid "`::rt::cache` Type descriptor cache"
6256 msgstr ""
6257
6258 #. type: Bullet: '* '
6259 #: doc/rust.md:3328
6260 msgid "`::rt::upcall` Compiler-generated runtime calls"
6261 msgstr ""
6262
6263 #. type: Bullet: '* '
6264 #: doc/rust.md:3328
6265 msgid "`::rt::timer` The scheduler timer"
6266 msgstr ""
6267
6268 #. type: Bullet: '* '
6269 #: doc/rust.md:3328
6270 msgid "`::rt::gc` Garbage collection"
6271 msgstr ""
6272
6273 #. type: Bullet: '* '
6274 #: doc/rust.md:3328
6275 msgid "`::rt::stdlib` Functions used directly by the standard library"
6276 msgstr ""
6277
6278 #. type: Bullet: '* '
6279 #: doc/rust.md:3328
6280 msgid "`::rt::kern` The runtime kernel"
6281 msgstr ""
6282
6283 #. type: Bullet: '* '
6284 #: doc/rust.md:3328
6285 msgid "`::rt::backtrace` Log a backtrace on task failure"
6286 msgstr ""
6287
6288 #. type: Bullet: '* '
6289 #: doc/rust.md:3328
6290 msgid "`::rt::callback` Unused"
6291 msgstr ""
6292
6293 #. type: Plain text
6294 #: doc/rust.md:3330
6295 msgid "#### Logging Expressions"
6296 msgstr ""
6297
6298 #. type: Plain text
6299 #: doc/rust.md:3333
6300 msgid ""
6301 "Rust provides several macros to log information. Here's a simple Rust "
6302 "program that demonstrates all four of them:"
6303 msgstr ""
6304
6305 #. type: Plain text
6306 #: doc/rust.md:3342
6307 #, no-wrap
6308 msgid ""
6309 "```rust\n"
6310 "fn main() {\n"
6311 "    error!(\"This is an error log\")\n"
6312 "    warn!(\"This is a warn log\")\n"
6313 "    info!(\"this is an info log\")\n"
6314 "    debug!(\"This is a debug log\")\n"
6315 "}\n"
6316 "```\n"
6317 msgstr ""
6318
6319 #. type: Plain text
6320 #: doc/rust.md:3344
6321 msgid ""
6322 "These four log levels correspond to levels 1-4, as controlled by `RUST_LOG`:"
6323 msgstr ""
6324
6325 #. type: Plain text
6326 #: doc/rust.md:3351
6327 msgid ""
6328 "```bash $ RUST_LOG=rust=3 ./rust rust: ~\"\\\"This is an error log\\\"\" "
6329 "rust: ~\"\\\"This is a warn log\\\"\" rust: ~\"\\\"this is an info log\\\"\" "
6330 "```"
6331 msgstr ""
6332
6333 #. type: Plain text
6334 #: doc/rust.md:3353
6335 msgid "# Appendix: Rationales and design tradeoffs"
6336 msgstr ""
6337
6338 #. type: Plain text
6339 #: doc/rust.md:3355
6340 #, no-wrap
6341 msgid "*TODO*.\n"
6342 msgstr ""
6343
6344 #. type: Plain text
6345 #: doc/rust.md:3357
6346 msgid "# Appendix: Influences and further references"
6347 msgstr ""
6348
6349 #. type: Plain text
6350 #: doc/rust.md:3359
6351 msgid "## Influences"
6352 msgstr ""
6353
6354 #. type: Plain text
6355 #: doc/rust.md:3368
6356 msgid ""
6357 "> The essential problem that must be solved in making a fault-tolerant > "
6358 "software system is therefore that of fault-isolation. Different programmers "
6359 "> will write different modules, some modules will be correct, others will "
6360 "have > errors. We do not want the errors in one module to adversely affect "
6361 "the > behaviour of a module which does not have any errors.  > > &mdash; Joe "
6362 "Armstrong"
6363 msgstr ""
6364
6365 #. type: Plain text
6366 #: doc/rust.md:3380
6367 msgid ""
6368 "> In our approach, all data is private to some process, and processes can > "
6369 "only communicate through communications channels. *Security*, as used > in "
6370 "this paper, is the property which guarantees that processes in a system > "
6371 "cannot affect each other except by explicit communication.  > > When "
6372 "security is absent, nothing which can be proven about a single module > in "
6373 "isolation can be guaranteed to hold when that module is embedded in a > "
6374 "system [...] > > &mdash; Robert Strom and Shaula Yemini"
6375 msgstr ""
6376
6377 #. type: Plain text
6378 #: doc/rust.md:3388
6379 msgid ""
6380 "> Concurrent and applicative programming complement each other. The > "
6381 "ability to send messages on channels provides I/O without side effects, > "
6382 "while the avoidance of shared data helps keep concurrent processes from > "
6383 "colliding.  > > &mdash; Rob Pike"
6384 msgstr ""
6385
6386 #. type: Plain text
6387 #: doc/rust.md:3395
6388 msgid ""
6389 "Rust is not a particularly original language. It may however appear unusual "
6390 "by contemporary standards, as its design elements are drawn from a number of "
6391 "\"historical\" languages that have, with a few exceptions, fallen out of "
6392 "favour. Five prominent lineages contribute the most, though their influences "
6393 "have come and gone during the course of Rust's development:"
6394 msgstr ""
6395
6396 #. type: Bullet: '* '
6397 #: doc/rust.md:3399
6398 msgid ""
6399 "The NIL (1981) and Hermes (1990) family. These languages were developed by "
6400 "Robert Strom, Shaula Yemini, David Bacon and others in their group at IBM "
6401 "Watson Research Center (Yorktown Heights, NY, USA)."
6402 msgstr ""
6403
6404 #. type: Bullet: '* '
6405 #: doc/rust.md:3403
6406 msgid ""
6407 "The Erlang (1987) language, developed by Joe Armstrong, Robert Virding, "
6408 "Claes Wikstr&ouml;m, Mike Williams and others in their group at the Ericsson "
6409 "Computer Science Laboratory (&Auml;lvsj&ouml;, Stockholm, Sweden) ."
6410 msgstr ""
6411
6412 #. type: Bullet: '* '
6413 #: doc/rust.md:3408
6414 msgid ""
6415 "The Sather (1990) language, developed by Stephen Omohundro, Chu-Cheow Lim, "
6416 "Heinz Schmidt and others in their group at The International Computer "
6417 "Science Institute of the University of California, Berkeley (Berkeley, CA, "
6418 "USA)."
6419 msgstr ""
6420
6421 #. type: Bullet: '* '
6422 #: doc/rust.md:3413
6423 msgid ""
6424 "The Newsqueak (1988), Alef (1995), and Limbo (1996) family. These languages "
6425 "were developed by Rob Pike, Phil Winterbottom, Sean Dorward and others in "
6426 "their group at Bell Labs Computing Sciences Research Center (Murray Hill, "
6427 "NJ, USA)."
6428 msgstr ""
6429
6430 #. type: Bullet: '* '
6431 #: doc/rust.md:3417
6432 msgid ""
6433 "The Napier (1985) and Napier88 (1988) family. These languages were developed "
6434 "by Malcolm Atkinson, Ron Morrison and others in their group at the "
6435 "University of St. Andrews (St. Andrews, Fife, UK)."
6436 msgstr ""
6437
6438 #. type: Plain text
6439 #: doc/rust.md:3419
6440 msgid ""
6441 "Additional specific influences can be seen from the following languages:"
6442 msgstr ""
6443
6444 #. type: Bullet: '* '
6445 #: doc/rust.md:3427
6446 msgid "The stack-growth implementation of Go."
6447 msgstr ""
6448
6449 #. type: Bullet: '* '
6450 #: doc/rust.md:3427
6451 msgid "The structural algebraic types and compilation manager of SML."
6452 msgstr ""
6453
6454 #. type: Bullet: '* '
6455 #: doc/rust.md:3427
6456 msgid "The attribute and assembly systems of C#."
6457 msgstr ""
6458
6459 #. type: Bullet: '* '
6460 #: doc/rust.md:3427
6461 msgid "The references and deterministic destructor system of C++."
6462 msgstr ""
6463
6464 #. type: Bullet: '* '
6465 #: doc/rust.md:3427
6466 msgid "The memory region systems of the ML Kit and Cyclone."
6467 msgstr ""
6468
6469 #. type: Bullet: '* '
6470 #: doc/rust.md:3427
6471 msgid "The typeclass system of Haskell."
6472 msgstr ""
6473
6474 #. type: Bullet: '* '
6475 #: doc/rust.md:3427
6476 msgid "The lexical identifier rule of Python."
6477 msgstr ""
6478
6479 #. type: Bullet: '* '
6480 #: doc/rust.md:3427
6481 msgid "The block syntax of Ruby."
6482 msgstr ""