Skip to content

Commit dc56e79

Browse files
authored
Merge pull request #411 from JoshBrudnak/bool-section
Added bool type section
2 parents 65e9b3d + fe98528 commit dc56e79

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Diff for: src/types.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Some types are defined by the language, rather than as part of the standard
1313
library, these are called _primitive types_. Some of these are individual
1414
types:
1515

16-
* The boolean type `bool` with values `true` and `false`.
16+
* The [boolean type] `bool` with values `true` and `false`.
1717
* The [machine types] (integer and floating-point).
1818
* The [machine-dependent integer types].
1919
* The [textual types] `char` and `str`.
@@ -29,6 +29,7 @@ language:
2929
* [References]
3030
* [Pointers]
3131

32+
[boolean type]: #boolean-type
3233
[machine types]: #machine-types
3334
[machine-dependent integer types]: #machine-dependent-integer-types
3435
[textual types]: #textual-types
@@ -42,18 +43,36 @@ language:
4243
[function]: #function-types
4344
[closure]: #closure-types
4445

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+
4564
## Numeric types
4665

4766
### Machine types
4867

4968
The machine types are the following:
5069

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],
5372
[0, 2^64 - 1], and [0, 2^128 - 1] respectively.
5473

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],
5776
[-(2^15), 2^15 - 1], [-(2^31), 2^31 - 1], [-(2^63), 2^63 - 1], and
5877
[-(2^127), 2^127 - 1] respectively.
5978

0 commit comments

Comments
 (0)