@@ -37,9 +37,9 @@ like `if` and `while` are available:
37
37
38
38
Though it isn't apparent in most everyday code, there is a fundamental
39
39
difference between Rust's syntax and the predecessors in this family
40
- of languages. Almost everything in rust is an expression, even things
41
- that are statements in other languages . This allows for useless things
42
- like this (which passes nil—the void type—to a function):
40
+ of languages. A lot of thing that are statements in C are expressions
41
+ in Rust . This allows for useless things like this (which passes
42
+ nil—the void type—to a function):
43
43
44
44
a_function(while false {});
45
45
@@ -62,11 +62,14 @@ This also works for function bodies. This function returns a boolean:
62
62
63
63
fn is_four(x: int) -> bool { x == 4 }
64
64
65
- If everything is an expression, you might conclude that you have to
66
- add a terminating semicolon after * every* statement, even ones that
65
+ In short, everything that's not a declaration (` let ` for variables,
66
+ ` fn ` for functions, etcetera) is an expression.
67
+
68
+ If all those things are expressions, you might conclude that you have
69
+ to add a terminating semicolon after * every* statement, even ones that
67
70
are not traditionally terminated with a semicolon in C (like ` while ` ).
68
- That is not the case, though. Statements that end in a block only need
69
- a semicolon if that block contains a trailing expression. ` while `
71
+ That is not the case, though. Expressions that end in a block only
72
+ need a semicolon if that block contains a trailing expression. ` while `
70
73
loops do not allow trailing expressions, and ` if ` statements tend to
71
74
only have a trailing expression when you want to use their value for
72
75
something—in which case you'll have embedded it in a bigger statement,
@@ -166,7 +169,7 @@ Integers can be written in decimal (`144`), hexadecimal (`0x90`), and
166
169
binary (` 0b10010000 ` ) base. Without suffix, an integer literal is
167
170
considered to be of type ` int ` . Add a ` u ` (` 144u ` ) to make it a ` uint `
168
171
instead. Literals of the fixed-size integer types can be created by
169
- the literal with the type name (` i8 ` , ` u64 ` , etc).
172
+ the literal with the type name (` 255u8 ` , ` 50i64 ` , etc).
170
173
171
174
Note that, in Rust, no implicit conversion between integer types
172
175
happens. If you are adding one to a variable of type ` uint ` , you must
@@ -188,12 +191,16 @@ character escapes, using the backslash character:
188
191
189
192
` \n `
190
193
: A newline (unicode character 32).
194
+
191
195
` \r `
192
196
: A carriage return (13).
197
+
193
198
` \t `
194
199
: A tab character (9).
200
+
195
201
` \\ ` , ` \' ` , ` \" `
196
202
: Simply escapes the following character.
203
+
197
204
` \xHH ` , ` \uHHHH ` , ` \UHHHHHHHH `
198
205
: Unicode escapes, where the ` H ` characters are the hexadecimal digits that form the character code.
199
206
0 commit comments