From fa72371bc7f537e0ae367494faf0721dc8db0b32 Mon Sep 17 00:00:00 2001 From: JoshBrudnak Date: Sat, 1 Sep 2018 08:24:34 -0400 Subject: [PATCH 1/3] Add section on the boolean type #238 --- src/types.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/types.md b/src/types.md index 68c2988c9..3808a8f64 100644 --- a/src/types.md +++ b/src/types.md @@ -13,7 +13,7 @@ Some types are defined by the language, rather than as part of the standard library, these are called _primitive types_. Some of these are individual types: -* The boolean type `bool` with values `true` and `false`. +* The [boolean type] `bool` with values `true` and `false`. * The [machine types] (integer and floating-point). * The [machine-dependent integer types]. * The [textual types] `char` and `str`. @@ -29,6 +29,7 @@ language: * [References] * [Pointers] +[boolean type]: #boolean-type [machine types]: #machine-types [machine-dependent integer types]: #machine-dependent-integer-types [textual types]: #textual-types @@ -44,6 +45,24 @@ language: ## Numeric types +### Boolean type + +The `bool` type is a datatype which can be either `true` or `false`. The boolean +type uses one byte of memory. It is used in comparisons and bitwise operations +like `&`, `|`, and `!`. + +```rust +fn main() { + let x = true; + let y: bool = false; // with the boolean type annotation + + // Use of booleans in conditional expressions + if x { + println!("x is true"); + } +} +``` + ### Machine types The machine types are the following: From 3955fe35352b5146304909e5e919c86241319ba9 Mon Sep 17 00:00:00 2001 From: JoshBrudnak Date: Sat, 1 Sep 2018 08:29:46 -0400 Subject: [PATCH 2/3] Formatted lines that passed 80 chars in types.md --- src/types.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/types.md b/src/types.md index 3808a8f64..7a7d6c5aa 100644 --- a/src/types.md +++ b/src/types.md @@ -67,12 +67,12 @@ fn main() { The machine types are the following: -* The unsigned word types `u8`, `u16`, `u32`, `u64`, and `u128` with values drawn from - the integer intervals [0, 2^8 - 1], [0, 2^16 - 1], [0, 2^32 - 1], +* The unsigned word types `u8`, `u16`, `u32`, `u64`, and `u128` with values + drawn from the integer intervals [0, 2^8 - 1], [0, 2^16 - 1], [0, 2^32 - 1], [0, 2^64 - 1], and [0, 2^128 - 1] respectively. -* The signed two's complement word types `i8`, `i16`, `i32`, `i64`, and `i128`, with - values drawn from the integer intervals [-(2^7), 2^7 - 1], +* The signed two's complement word types `i8`, `i16`, `i32`, `i64`, and `i128`, + with values drawn from the integer intervals [-(2^7), 2^7 - 1], [-(2^15), 2^15 - 1], [-(2^31), 2^31 - 1], [-(2^63), 2^63 - 1], and [-(2^127), 2^127 - 1] respectively. From fe9852849f90ca3d747dd3049f0ff7a64dbe7843 Mon Sep 17 00:00:00 2001 From: JoshBrudnak Date: Sat, 1 Sep 2018 11:36:09 -0400 Subject: [PATCH 3/3] moved bool out of numeric types --- src/types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types.md b/src/types.md index 7a7d6c5aa..a39ba2781 100644 --- a/src/types.md +++ b/src/types.md @@ -43,8 +43,6 @@ language: [function]: #function-types [closure]: #closure-types -## Numeric types - ### Boolean type The `bool` type is a datatype which can be either `true` or `false`. The boolean @@ -63,6 +61,8 @@ fn main() { } ``` +## Numeric types + ### Machine types The machine types are the following: