Skip to content

Commit 201039c

Browse files
committed
tutorial: Discuss the primitive types along with their literals
1 parent 107b2e5 commit 201039c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

doc/tutorial.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ let my_variable = 100;
249249
type MyType = int; // some built-in types are _not_ camel case
250250
~~~
251251

252-
## Expression syntax
252+
## Expressions and semicolons
253253

254254
Though it isn't apparent in all code, there is a fundamental
255255
difference between Rust's syntax and predecessors like C.
@@ -308,12 +308,14 @@ fn is_four(x: int) -> bool {
308308
}
309309
~~~~
310310

311-
## Literals
311+
## Primitive types and literals
312312

313+
There are general signed and unsigned integer types, `int`, and `uint`,
314+
as well as 8-, 16-, 32-, and 64-bit variations, `i8`, `u16`, etc.
313315
Integers can be written in decimal (`144`), hexadecimal (`0x90`), or
314316
binary (`0b10010000`) base. Each integral type has a corresponding literal
315317
suffix that can be used to indicate the type of a literal: `i` for `int`,
316-
`u` for `uint`, and `i8` for the `i8` type, etc.
318+
`u` for `uint`, `i8` for the `i8` type.
317319

318320
In the absence of an integer literal suffix, Rust will infer the
319321
integer type based on type annotations and function signatures in the
@@ -328,19 +330,21 @@ let c = 100u; // c is a uint
328330
let d = 1000i32; // d is an i32
329331
~~~~
330332

331-
Floating point numbers are written `0.0`, `1e6`, or `2.1e-4`. Without
332-
a suffix, the literal is assumed to be of type `float`. Suffixes `f32`
333-
(32-bit) and `f64` (64-bit) can be used to create literals of a
334-
specific type.
333+
There are three floating point types, `float`, `f32`, and `f64`.
334+
Floating point numbers are written `0.0`, `1e6`, or `2.1e-4`.
335+
Like integers, floating point literals are inferred to the correct type.
336+
Suffixes `f`, `f32` and `f64` can be used to create literals of a specific type.
335337

336-
The unit literal is written just like the type: `()`. The keywords
337-
`true` and `false` produce the boolean literals.
338+
The keywords `true` and `false` produce literals of type `bool`.
338339

339-
Character literals are written between single quotes, as in `'x'`. Just like
340-
C, Rust understands a number of character escapes, using the backslash
340+
Characters, the `char` type, are 4-byte unicode codepoints,
341+
whose literals are written between single quotes, as in `'x'`.
342+
Just like C, Rust understands a number of character escapes, using the backslash
341343
character, such as `\n`, `\r`, and `\t`. String literals,
342-
written between double quotes, allow the same escape sequences. Rust strings
343-
may contain newlines.
344+
written between double quotes, allow the same escape sequences.
345+
More on strings [later](#vectors-and-strings).
346+
347+
The nil type, written `()`, has a single value, also written `()`.
344348

345349
## Operators
346350

0 commit comments

Comments
 (0)