Skip to content

Commit fa72371

Browse files
committed
Add section on the boolean type rust-lang#238
1 parent 85df178 commit fa72371

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/types.md

Lines changed: 20 additions & 1 deletion
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
@@ -44,6 +45,24 @@ language:
4445

4546
## Numeric types
4647

48+
### Boolean type
49+
50+
The `bool` type is a datatype which can be either `true` or `false`. The boolean
51+
type uses one byte of memory. It is used in comparisons and bitwise operations
52+
like `&`, `|`, and `!`.
53+
54+
```rust
55+
fn main() {
56+
let x = true;
57+
let y: bool = false; // with the boolean type annotation
58+
59+
// Use of booleans in conditional expressions
60+
if x {
61+
println!("x is true");
62+
}
63+
}
64+
```
65+
4766
### Machine types
4867

4968
The machine types are the following:

0 commit comments

Comments
 (0)