@@ -13,7 +13,7 @@ Some types are defined by the language, rather than as part of the standard
13
13
library, these are called _ primitive types_ . Some of these are individual
14
14
types:
15
15
16
- * The boolean type ` bool ` with values ` true ` and ` false ` .
16
+ * The [ boolean type] ` bool ` with values ` true ` and ` false ` .
17
17
* The [ machine types] (integer and floating-point).
18
18
* The [ machine-dependent integer types] .
19
19
* The [ textual types] ` char ` and ` str ` .
@@ -29,6 +29,7 @@ language:
29
29
* [ References]
30
30
* [ Pointers]
31
31
32
+ [ boolean type ] : #boolean-type
32
33
[ machine types ] : #machine-types
33
34
[ machine-dependent integer types ] : #machine-dependent-integer-types
34
35
[ textual types ] : #textual-types
@@ -42,18 +43,36 @@ language:
42
43
[ function ] : #function-types
43
44
[ closure ] : #closure-types
44
45
46
+ ### Boolean type
47
+
48
+ The ` bool ` type is a datatype which can be either ` true ` or ` false ` . The boolean
49
+ type uses one byte of memory. It is used in comparisons and bitwise operations
50
+ like ` & ` , ` | ` , and ` ! ` .
51
+
52
+ ``` rust
53
+ fn main () {
54
+ let x = true ;
55
+ let y : bool = false ; // with the boolean type annotation
56
+
57
+ // Use of booleans in conditional expressions
58
+ if x {
59
+ println! (" x is true" );
60
+ }
61
+ }
62
+ ```
63
+
45
64
## Numeric types
46
65
47
66
### Machine types
48
67
49
68
The machine types are the following:
50
69
51
- * The unsigned word types ` u8 ` , ` u16 ` , ` u32 ` , ` u64 ` , and ` u128 ` with values drawn from
52
- the integer intervals [ 0, 2^8 - 1] , [ 0, 2^16 - 1] , [ 0, 2^32 - 1] ,
70
+ * The unsigned word types ` u8 ` , ` u16 ` , ` u32 ` , ` u64 ` , and ` u128 ` with values
71
+ drawn from the integer intervals [ 0, 2^8 - 1] , [ 0, 2^16 - 1] , [ 0, 2^32 - 1] ,
53
72
[ 0, 2^64 - 1] , and [ 0, 2^128 - 1] respectively.
54
73
55
- * The signed two's complement word types ` i8 ` , ` i16 ` , ` i32 ` , ` i64 ` , and ` i128 ` , with
56
- values drawn from the integer intervals [ -(2^7), 2^7 - 1] ,
74
+ * The signed two's complement word types ` i8 ` , ` i16 ` , ` i32 ` , ` i64 ` , and ` i128 ` ,
75
+ with values drawn from the integer intervals [ -(2^7), 2^7 - 1] ,
57
76
[ -(2^15), 2^15 - 1] , [ -(2^31), 2^31 - 1] , [ -(2^63), 2^63 - 1] , and
58
77
[ -(2^127), 2^127 - 1] respectively.
59
78
0 commit comments