Skip to content

Minor fixes (whitespace, typo, i32->u32) #1947

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 5 commits into from
Aug 2, 2025
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
2 changes: 1 addition & 1 deletion po/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ msgstr "Sacando `Result`s de `Option`s"

#: src/SUMMARY.md:172 src/error/multiple_error_types/define_error_type.md:1
msgid "Defining an error type"
msgstr "Defniniendo un tipo de error"
msgstr "Definiendo un tipo de error"

#: src/SUMMARY.md:173 src/error/multiple_error_types/boxing_errors.md:1
msgid "`Box`ing errors"
Expand Down
2 changes: 1 addition & 1 deletion src/crates/using_lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
```txt
# Where library.rlib is the path to the compiled library, assumed that it's
# in the same directory here:
$ rustc executable.rs --extern rary=library.rlib && ./executable
$ rustc executable.rs --extern rary=library.rlib && ./executable
called rary's `public_function()`
called rary's `indirect_access()`, that
> called rary's `private_function()`
Expand Down
4 changes: 2 additions & 2 deletions src/custom_types/enum/c_like.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ fn main() {
println!("zero is {}", Number::Zero as i32);
println!("one is {}", Number::One as i32);

println!("roses are #{:06x}", Color::Red as i32);
println!("violets are #{:06x}", Color::Blue as i32);
println!("roses are #{:06x}", Color::Red as u32);
println!("violets are #{:06x}", Color::Blue as u32);
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/custom_types/enum/testcase_linked_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl List {
// `self` has type `&List`, and `*self` has type `List`, matching on a
// concrete type `T` is preferred over a match on a reference `&T`
// after Rust 2018 you can use self here and tail (with no ref) below as well,
// rust will infer &s and ref tail.
// rust will infer &s and ref tail.
// See https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/default-match-bindings.html
match *self {
// Can't take ownership of the tail, because `self` is borrowed;
Expand Down
2 changes: 1 addition & 1 deletion src/error/abort_unwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The previous section illustrates the error handling mechanism `panic`. Different code paths can be conditionally compiled based on the panic setting. The current values available are `unwind` and `abort`.

Building on the prior lemonade example, we explicitly use the panic strategy to exercise different lines of code.
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/error/option_unwrap/and_then.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ known in some languages as flatmap, comes in.
`and_then()` calls its function input with the wrapped value and returns the result. If the `Option` is `None`, then it returns `None` instead.

In the following example, `cookable_v3()` results in an `Option<Food>`.
Using `map()` instead of `and_then()` would have given an
Using `map()` instead of `and_then()` would have given an
`Option<Option<Food>>`, which is an invalid type for `eat()`.

```rust,editable
Expand Down
8 changes: 4 additions & 4 deletions src/error/option_unwrap/defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There is more than one way to unpack an `Option` and fall back on a default if i
`or()`is chainable and eagerly evaluates its argument, as is shown in the following example. Note that because `or`'s arguments are evaluated eagerly, the variable passed to `or` is moved.

```rust,editable
#[derive(Debug)]
#[derive(Debug)]
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }

fn main() {
Expand All @@ -27,15 +27,15 @@ fn main() {
// But the variable named `apple` has been moved regardless, and cannot be used anymore.
// println!("Variable apple was moved, so this line won't compile: {:?}", apple);
// TODO: uncomment the line above to see the compiler error
}
}
```

## `or_else()` is chainable, evaluates lazily, keeps empty value intact

Another alternative is to use `or_else`, which is also chainable, and evaluates lazily, as is shown in the following example:

```rust,editable
#[derive(Debug)]
#[derive(Debug)]
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }

fn main() {
Expand Down Expand Up @@ -84,7 +84,7 @@ fn main() {
Instead of explicitly providing a value to fall back on, we can pass a closure to `get_or_insert_with`, as follows:

```rust,editable
#[derive(Debug)]
#[derive(Debug)]
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/error/result/enter_question_mark.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ at older code. The same `multiply` function from the previous example
would look like this using `try!`:

```rust,editable,edition2015
// To compile and run this example without errors, while using Cargo, change the value
// To compile and run this example without errors, while using Cargo, change the value
// of the `edition` field, in the `[package]` section of the `Cargo.toml` file, to "2015".

use std::num::ParseIntError;
Expand Down
4 changes: 2 additions & 2 deletions src/flow_control/for.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn main() {
_ => println!("Hello {}", name),
}
}

println!("names: {:?}", names);
}
```
Expand All @@ -90,7 +90,7 @@ fn main() {
_ => println!("Hello {}", name),
}
}

println!("names: {:?}", names);
// FIXME ^ Comment out this line
}
Expand Down
6 changes: 3 additions & 3 deletions src/flow_control/if_let.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ fn main() {
let a = Foo::Bar;
let b = Foo::Baz;
let c = Foo::Qux(100);

// Variable a matches Foo::Bar
if let Foo::Bar = a {
println!("a is foobar");
}

// Variable b does not match Foo::Bar
// So this will print nothing
if let Foo::Bar = b {
println!("b is foobar");
}

// Variable c matches Foo::Qux which has a value
// Similar to Some() in the previous example
if let Foo::Qux(value) = c {
Expand Down
4 changes: 2 additions & 2 deletions src/flow_control/let_else.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ patterns with an unfortunate bit of repetition and an outer `let`:

```rust
# use std::str::FromStr;
#
#
# fn get_count_item(s: &str) -> (u64, &str) {
# let mut it = s.split(' ');
let (count_str, item) = match (it.next(), it.next()) {
Expand All @@ -48,7 +48,7 @@ patterns with an unfortunate bit of repetition and an outer `let`:
};
# (count, item)
# }
#
#
# assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
```

Expand Down
2 changes: 1 addition & 1 deletion src/flow_control/while_let.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Using `while let` makes this sequence much nicer:
fn main() {
// Make `optional` of type `Option<i32>`
let mut optional = Some(0);

// This reads: "while `let` destructures `optional` into
// `Some(i)`, evaluate the block (`{}`). Else `break`.
while let Some(i) = optional {
Expand Down
2 changes: 1 addition & 1 deletion src/fn/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Other characteristics of closures include:
```rust,editable
fn main() {
let outer_var = 42;

// A regular function can't refer to variables in the enclosing environment
//fn function(i: i32) -> i32 { i + outer_var }
// TODO: uncomment the line above and see the compiler error. The compiler
Expand Down
14 changes: 7 additions & 7 deletions src/fn/closures/capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ required.
```rust,editable
fn main() {
use std::mem;

let color = String::from("green");

// A closure to print `color` which immediately borrows (`&`) `color` and
// stores the borrow and closure in the `print` variable. It will remain
// borrowed until `print` is used the last time.
// borrowed until `print` is used the last time.
//
// `println!` only requires arguments by immutable reference so it doesn't
// impose anything more restrictive.
Expand All @@ -30,7 +30,7 @@ fn main() {
print();

// `color` can be borrowed immutably again, because the closure only holds
// an immutable reference to `color`.
// an immutable reference to `color`.
let _reborrow = &color;
print();

Expand All @@ -55,15 +55,15 @@ fn main() {

// The closure still mutably borrows `count` because it is called later.
// An attempt to reborrow will lead to an error.
// let _reborrow = &count;
// let _reborrow = &count;
// ^ TODO: try uncommenting this line.
inc();

// The closure no longer needs to borrow `&mut count`. Therefore, it is
// possible to reborrow without an error
let _count_reborrowed = &mut count;
let _count_reborrowed = &mut count;



// A non-copy type.
let movable = Box::new(3);

Expand Down Expand Up @@ -100,7 +100,7 @@ fn main() {
// ^ Uncommenting above line will result in compile-time error
// because borrow checker doesn't allow re-using variable after it
// has been moved.

// Removing `move` from closure's signature will cause closure
// to borrow _haystack_ variable immutably, hence _haystack_ is still
// available and uncommenting above line will not cause an error.
Expand Down
4 changes: 2 additions & 2 deletions src/fn/closures/closure_examples/iter_find.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ fn main() {
// we have to destructure `&i32` to `i32`
let index_of_first_even_number = vec.iter().position(|&x| x % 2 == 0);
assert_eq!(index_of_first_even_number, Some(5));

// `into_iter()` for vecs yields `i32` and `position()` does not take a reference, so
// we do not have to destructure
// we do not have to destructure
let index_of_first_negative_number = vec.into_iter().position(|x| x < 0);
assert_eq!(index_of_first_negative_number, None);
}
Expand Down
2 changes: 1 addition & 1 deletion src/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct SingleGen<T>(T);
fn main() {
// `Single` is concrete and explicitly takes `A`.
let _s = Single(A);

// Create a variable `_char` of type `SingleGen<char>`
// and give it the value `SingleGen('a')`.
// Here, `SingleGen` has a type parameter explicitly specified.
Expand Down
2 changes: 1 addition & 1 deletion src/generics/assoc_items/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn main() {
container.contains(&number_1, &number_2));
println!("First number: {}", container.first());
println!("Last number: {}", container.last());

println!("The difference is: {}", difference(&container));
}
```
2 changes: 1 addition & 1 deletion src/generics/bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn main() {
//print_debug(&_triangle);
//println!("Area: {}", area(&_triangle));
// ^ TODO: Try uncommenting these.
// | Error: Does not implement either `Debug` or `HasArea`.
// | Error: Does not implement either `Debug` or `HasArea`.
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/generics/gen_fn.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct SGen<T>(T); // Generic type `SGen`.
fn reg_fn(_s: S) {}

// Define a function `gen_spec_t` that takes an argument `_s` of type `SGen<T>`.
// It has been explicitly given the type parameter `A`, but because `A` has not
// It has been explicitly given the type parameter `A`, but because `A` has not
// been specified as a generic type parameter for `gen_spec_t`, it is not generic.
fn gen_spec_t(_s: SGen<A>) {}

Expand Down
2 changes: 1 addition & 1 deletion src/generics/where.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait PrintInOption {
fn print_in_option(self);
}

// Because we would otherwise have to express this as `T: Debug` or
// Because we would otherwise have to express this as `T: Debug` or
// use another method of indirect approach, this requires a `where` clause:
impl<T> PrintInOption for T where
Option<T>: Debug {
Expand Down
12 changes: 6 additions & 6 deletions src/mod/super.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ mod my {
fn function() {
println!("called `my::function()`");
}

mod cool {
pub fn function() {
println!("called `my::cool::function()`");
}
}

pub fn indirect_call() {
// Let's access all the functions named `function` from this scope!
print!("called `my::indirect_call()`, that\n> ");

// The `self` keyword refers to the current module scope - in this case `my`.
// Calling `self::function()` and calling `function()` directly both give
// the same result, because they refer to the same function.
self::function();
function();

// We can also use `self` to access another module inside `my`:
self::cool::function();

// The `super` keyword refers to the parent scope (outside the `my` module).
super::function();

// This will bind to the `cool::function` in the *crate* scope.
// In this case the crate scope is the outermost scope.
{
Expand Down
2 changes: 1 addition & 1 deletion src/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn main() {
// Array signature consists of Type T and length as [T; length].
let my_array: [i32; 5] = [1, 2, 3, 4, 5];

// Tuple is a collection of values of different types
// Tuple is a collection of values of different types
// and is constructed using parentheses ().
let my_tuple = (5u32, 1u8, true, -5.04f32);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scope/borrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn borrow_i32(borrowed_i32: &i32) {
}

fn main() {
// Create a boxed i32 in the heap, and a i32 on the stack
// Create a boxed i32 in the heap, and an i32 on the stack
// Remember: numbers can have arbitrary underscores added for readability
// 5_i32 is the same as 5i32
let boxed_i32 = Box::new(5_i32);
Expand Down
6 changes: 3 additions & 3 deletions src/scope/borrow/mut.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ fn main() {

// Create a mutable copy of `immutabook` and call it `mutabook`
let mut mutabook = immutabook;

// Immutably borrow an immutable object
borrow_book(&immutabook);

// Immutably borrow a mutable object
borrow_book(&mutabook);

// Borrow a mutable object as mutable
new_edition(&mut mutabook);

// Error! Cannot borrow an immutable object as mutable
new_edition(&mut immutabook);
// FIXME ^ Comment out this line
Expand Down
4 changes: 2 additions & 2 deletions src/scope/borrow/ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ fn main() {

// A mutable tuple that includes a pointer
let mut mutable_tuple = (Box::new(5u32), 3u32);

{
// Destructure `mutable_tuple` to change the value of `last`.
let (_, ref mut last) = mutable_tuple;
*last = 2u32;
}

println!("tuple is {:?}", mutable_tuple);
}
```
4 changes: 2 additions & 2 deletions src/scope/lifetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ lifetimes relate to scopes, as well as how the two differ.
```rust,editable
// Lifetimes are annotated below with lines denoting the creation
// and destruction of each variable.
// `i` has the longest lifetime because its scope entirely encloses
// both `borrow1` and `borrow2`. The duration of `borrow1` compared
// `i` has the longest lifetime because its scope entirely encloses
// both `borrow1` and `borrow2`. The duration of `borrow1` compared
// to `borrow2` is irrelevant since they are disjoint.
fn main() {
let i = 3; // Lifetime for `i` starts. ────────────────┐
Expand Down
Loading