From b5602c746fa9114a39dfd7397feb9d2f62ba03e7 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 2 Aug 2016 21:50:46 -0400 Subject: [PATCH] Add a few more section headers to the tutorial --- src/ch02-00-guessing-game-tutorial.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index e4471dd3a..0ad4e27e1 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -111,6 +111,8 @@ println!("Please input your guess."); We previously learned in Chapter 1 that `println!()` is a macro that prints a string to the screen. +### Variable Bindings + ```rust,ignore let mut guess = String::new(); ``` @@ -223,7 +225,11 @@ io::stdin().read_line(&mut guess).expect("failed to read line"); ``` But that gets hard to read. So we’ve split it up, two lines for two method -calls. We already talked about `read_line()`, but what about `expect()`? Well, +calls. + +### The `Result` Type + +We already talked about `read_line()`, but what about `expect()`? Well, we already mentioned that `read_line()` puts what the user types into the `&mut String` we pass it. But it also returns a value: in this case, an [`io::Result`][ioresult]. Rust has a number of types named `Result` in its @@ -259,6 +265,8 @@ actually write error handling. Luckily, if we want to crash if there’s a problem, we can use `expect()`. If we can recover from the error somehow, we’d do something else, but we’ll save that for a future project. +### `println!()` Placeholders + There’s only one line of this first example left, aside from the closing curly brace: