Skip to content

Commit

Permalink
Move the 'new features' appendex into the text
Browse files Browse the repository at this point in the history
Fixes #1294
  • Loading branch information
steveklabnik committed Jun 8, 2018
1 parent a764e87 commit f22dace
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 132 deletions.
3 changes: 1 addition & 2 deletions 2018-edition/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,4 @@
- [C - Derivable Traits](appendix-03-derivable-traits.md)
- [D - Macros](appendix-04-macros.md)
- [E - Translations](appendix-05-translation.md)
- [F - Newest Features](appendix-06-newest-features.md)
- [G - How Rust is Made and “Nightly Rust”](appendix-07-nightly-rust.md)
- [F - How Rust is Made and “Nightly Rust”](appendix-06-nightly-rust.md)
128 changes: 0 additions & 128 deletions 2018-edition/src/appendix-06-newest-features.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Appendix G - How Rust is Made and “Nightly Rust”
# Appendix F - How Rust is Made and “Nightly Rust”

This appendix is about how Rust is made and how that affects you as a Rust
developer.
Expand Down
24 changes: 24 additions & 0 deletions 2018-edition/src/ch03-05-control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,30 @@ stop executing the loop. Recall that we did this in the guessing game in the
“Quitting After a Correct Guess” section of Chapter 2 to exit the
program when the user won the game by guessing the correct number.


#### Returning from loops

One of the uses of a `loop` is to retry an operation you know can fail, such as
checking if a thread completed its job. However, you might need to pass the
result of that operation to the rest of your code. If you add it to the `break`
expression you use to stop the loop, it will be returned by the broken loop:

```rust
fn main() {
let mut counter = 0;

let result = loop {
counter += 1;

if counter == 10 {
break counter * 2;
}
};

assert_eq!(result, 20);
}
```

#### Conditional Loops with `while`

It’s often useful for a program to evaluate a condition within a loop. While
Expand Down
13 changes: 12 additions & 1 deletion 2018-edition/src/ch04-03-slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,18 @@ let world = &s[6..11];
This is similar to taking a reference to the whole `String` but with the extra
`[0..5]` bit. Rather than a reference to the entire `String`, it’s a reference
to a portion of the `String`. The `start..end` syntax is a range that begins at
`start` and continues up to, but not including, `end`.
`start` and continues up to, but not including, `end`. If we wanted to include
`end`, we can use `..=` instead of `..`:

```rust
let s = String::from("hello world");

let hello = &s[0..=4];
let world = &s[6..=10];
```

The `=` means that we're including the last number, if that helps you remember
the difference between `..` and `..=`.

We can create slices using a range within brackets by specifying
`[starting_index..ending_index]`, where `starting_index` is the first position
Expand Down
33 changes: 33 additions & 0 deletions 2018-edition/src/ch07-03-importing-names-with-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ fn main() {
We’re still specifying the `TrafficLight` namespace for the `Green` variant
because we didn’t include `Green` in the `use` statement.

#### Nested groups in `use` declarations

If you have a complex module tree with many different submodules and you need
to import a few items from each one, it might be useful to group all the
imports in the same declaration to keep your code clean and avoid repeating the
base modules’ name.

The `use` declaration supports nesting to help you in those cases, both with
simple imports and glob ones. For example this snippets imports `bar`, `Foo`,
all the items in `baz` and `Bar`:

```rust
# #![allow(unused_imports, dead_code)]
#
# mod foo {
# pub mod bar {
# pub type Foo = ();
# }
# pub mod baz {
# pub mod quux {
# pub type Bar = ();
# }
# }
# }
#
use foo::{
bar::{self, Foo},
baz::{*, quux::Bar},
};
#
# fn main() {}
```

### Bringing All Names into Scope with a Glob

To bring all the items in a namespace into scope at once, we can use the `*`
Expand Down

0 comments on commit f22dace

Please sign in to comment.