Skip to content

Various minor edits for typo fixes, formatting fixes, and clarifications #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/error/abort_unwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ The previous section illustrates the error handling mechanism `panic`. Differen
Building on the prior lemonade example, we explicitly use the panic strategy to exercise different lines of code.

```rust,editable,mdbook-runnable

fn drink(beverage: &str) {
// You shouldn't drink too much sugary beverages.
// You shouldn't drink too much sugary beverages.
if beverage == "lemonade" {
if cfg!(panic="abort"){ println!("This is not your party. Run!!!!");}
else{ println!("Spit it out!!!!");}
if cfg!(panic = "abort") {
println!("This is not your party. Run!!!!");
} else {
println!("Spit it out!!!!");
}
} else {
println!("Some refreshing {} is all I need.", beverage);
}
else{ println!("Some refreshing {} is all I need.", beverage); }
}

fn main() {
Expand All @@ -25,16 +28,22 @@ fn main() {
Here is another example focusing on rewriting `drink()` and explicitly use the `unwind` keyword.

```rust,editable

#[cfg(panic = "unwind")]
fn ah(){ println!("Spit it out!!!!");}
fn ah() {
println!("Spit it out!!!!");
}

#[cfg(not(panic="unwind"))]
fn ah(){ println!("This is not your party. Run!!!!");}
#[cfg(not(panic = "unwind"))]
fn ah() {
println!("This is not your party. Run!!!!");
}

fn drink(beverage: &str){
if beverage == "lemonade"{ ah();}
else{println!("Some refreshing {} is all I need.", beverage);}
fn drink(beverage: &str) {
if beverage == "lemonade" {
ah();
} else {
println!("Some refreshing {} is all I need.", beverage);
}
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/error/multiple_error_types/boxing_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ via [`From`][from].
use std::error;
use std::fmt;

// Change the alias to `Box<error::Error>`.
// Change the alias to use `Box<dyn error::Error>`.
type Result<T> = std::result::Result<T, Box<dyn error::Error>>;

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/error/multiple_error_types/reenter_question_mark.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Here, we rewrite the previous example using `?`. As a result, the
use std::error;
use std::fmt;

// Change the alias to `Box<dyn error::Error>`.
// Change the alias to use `Box<dyn error::Error>`.
type Result<T> = std::result::Result<T, Box<dyn error::Error>>;

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/error/option_unwrap/defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Another alternative is to use `or_else`, which is also chainable, and evaluates
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }

fn main() {
let apple = Some(Fruit::Apple);
let no_fruit: Option<Fruit> = None;
let get_kiwi_as_fallback = || {
println!("Providing kiwi as fallback");
Expand Down
4 changes: 2 additions & 2 deletions src/flow_control/match/guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ fn main() {
match temperature {
Temperature::Celsius(t) if t > 30 => println!("{}C is above 30 Celsius", t),
// The `if condition` part ^ is a guard
Temperature::Celsius(t) => println!("{}C is below 30 Celsius", t),
Temperature::Celsius(t) => println!("{}C is equal to or below 30 Celsius", t),

Temperature::Fahrenheit(t) if t > 86 => println!("{}F is above 86 Fahrenheit", t),
Temperature::Fahrenheit(t) => println!("{}F is below 86 Fahrenheit", t),
Temperature::Fahrenheit(t) => println!("{}F is equal to or below 86 Fahrenheit", t),
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/fn/closures/capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
// borrows `count`.
//
// A `mut` is required on `inc` because a `&mut` is stored inside. Thus,
// calling the closure mutates the closure which requires a `mut`.
// calling the closure mutates `count` which requires a `mut`.
let mut inc = || {
count += 1;
println!("`count`: {}", count);
Expand Down
2 changes: 1 addition & 1 deletion src/macros/dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ an expression and have the output printed to console.
macro_rules! calculate {
(eval $e:expr) => {
{
let val: usize = $e; // Force types to be integers
let val: usize = $e; // Force types to be unsigned integers
println!("{} = {}", stringify!{$e}, val);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/meta/playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
```

This allows the reader to both run your code sample, but also modify and tweak
it. The key here is the adding the word `editable` to your codefence block
it. The key here is the adding of the word `editable` to your codefence block
separated by a comma.

````markdown
Expand Down
4 changes: 2 additions & 2 deletions src/trait/clone.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ fn main() {

// Clone `moved_pair` into `cloned_pair` (resources are included)
let cloned_pair = moved_pair.clone();
// Drop the original pair using std::mem::drop
// Drop the moved original pair using std::mem::drop
drop(moved_pair);

// Error! `moved_pair` has been dropped
//println!("copy: {:?}", moved_pair);
//println!("moved and dropped: {:?}", moved_pair);
// TODO ^ Try uncommenting this line

// The result from .clone() can still be used!
Expand Down
4 changes: 2 additions & 2 deletions src/trait/disambiguating.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Disambiguating overlapping traits

A type can implement many different traits. What if two traits both require
the same name? For example, many traits might have a method named `get()`.
They might even have different return types!
the same name for a function? For example, many traits might have a method
named `get()`. They might even have different return types!

Good news: because each trait implementation gets its own `impl` block, it's
clear which trait's `get` method you're implementing.
Expand Down