Skip to content

Commit

Permalink
[BOT] Updating 37fe8e1 content
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 7, 2024
1 parent 37fe8e1 commit 87a320f
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 74 deletions.
2 changes: 1 addition & 1 deletion rustbook-en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ before we merge any in, but feel free to start!
To scan source files for spelling errors, you can use the `spellcheck.sh`
script available in the `ci` directory. It needs a dictionary of valid words,
which is provided in `ci/dictionary.txt`. If the script produces a false
positive (say, you used word `BTreeMap` which the script considers invalid),
positive (say, you used the word `BTreeMap` which the script considers invalid),
you need to add this word to `ci/dictionary.txt` (keep the sorted order for
consistency).
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
panic!(
"Guess value must be greater than or equal to 1, got {}.",
value
"Guess value must be greater than or equal to 1, got {value}."
);
} else if value > 100 {
panic!(
"Guess value must be less than or equal to 100, got {}.",
value
"Guess value must be less than or equal to 100, got {value}."
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ impl Guess {
// ANCHOR: here
if value < 1 {
panic!(
"Guess value must be less than or equal to 100, got {}.",
value
"Guess value must be less than or equal to 100, got {value}."
);
} else if value > 100 {
panic!(
"Guess value must be greater than or equal to 1, got {}.",
value
"Guess value must be greater than or equal to 1, got {value}."
);
}
// ANCHOR_END: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $ cargo run
error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` closure
--> src/main.rs:18:30
|
15 | let value = String::from("by key called");
15 | let value = String::from("closure called");
| ----- captured outer variable
16 |
17 | list.sort_by_key(|r| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
];

let mut sort_operations = vec![];
let value = String::from("by key called");
let value = String::from("closure called");

list.sort_by_key(|r| {
sort_operations.push(value);
Expand Down
46 changes: 20 additions & 26 deletions rustbook-en/listings/ch20-web-server/listing-20-25/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use hello::ThreadPool;
use std::fs;
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
use std::thread;
use std::time::Duration;
use std::{
fs,
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
thread,
time::Duration,
};

// ANCHOR: here
fn main() {
Expand All @@ -24,30 +25,23 @@ fn main() {
// ANCHOR_END: here

fn handle_connection(mut stream: TcpStream) {
let mut buffer = [0; 1024];
stream.read(&mut buffer).unwrap();

let get = b"GET / HTTP/1.1\r\n";
let sleep = b"GET /sleep HTTP/1.1\r\n";

let (status_line, filename) = if buffer.starts_with(get) {
("HTTP/1.1 200 OK", "hello.html")
} else if buffer.starts_with(sleep) {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 200 OK", "hello.html")
} else {
("HTTP/1.1 404 NOT FOUND", "404.html")
let buf_reader = BufReader::new(&mut stream);
let request_line = buf_reader.lines().next().unwrap().unwrap();

let (status_line, filename) = match &request_line[..] {
"GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"),
"GET /sleep HTTP/1.1" => {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 200 OK", "hello.html")
}
_ => ("HTTP/1.1 404 NOT FOUND", "404.html"),
};

let contents = fs::read_to_string(filename).unwrap();
let length = contents.len();

let response = format!(
"{}\r\nContent-Length: {}\r\n\r\n{}",
status_line,
contents.len(),
contents
);
let response =
format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}");

stream.write_all(response.as_bytes()).unwrap();
stream.flush().unwrap();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use hello::ThreadPool;
use std::fs;
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
use std::thread;
use std::time::Duration;
use std::{
fs,
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
thread,
time::Duration,
};

fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
Expand All @@ -22,30 +23,23 @@ fn main() {
}

fn handle_connection(mut stream: TcpStream) {
let mut buffer = [0; 1024];
stream.read(&mut buffer).unwrap();

let get = b"GET / HTTP/1.1\r\n";
let sleep = b"GET /sleep HTTP/1.1\r\n";

let (status_line, filename) = if buffer.starts_with(get) {
("HTTP/1.1 200 OK", "hello.html")
} else if buffer.starts_with(sleep) {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 200 OK", "hello.html")
} else {
("HTTP/1.1 404 NOT FOUND", "404.html")
let buf_reader = BufReader::new(&mut stream);
let request_line = buf_reader.lines().next().unwrap().unwrap();

let (status_line, filename) = match &request_line[..] {
"GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"),
"GET /sleep HTTP/1.1" => {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 200 OK", "hello.html")
}
_ => ("HTTP/1.1 404 NOT FOUND", "404.html"),
};

let contents = fs::read_to_string(filename).unwrap();
let length = contents.len();

let response = format!(
"{}\r\nContent-Length: {}\r\n\r\n{}",
status_line,
contents.len(),
contents
);
let response =
format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}");

stream.write_all(response.as_bytes()).unwrap();
stream.flush().unwrap();
}
2 changes: 1 addition & 1 deletion rustbook-en/src/appendix-03-derivable-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The `Debug` trait allows you to print instances of a type for debugging
purposes, so you and other programmers using your type can inspect an instance
at a particular point in a program’s execution.

The `Debug` trait is required, for example, in use of the `assert_eq!` macro.
The `Debug` trait is required, for example, in using the `assert_eq!` macro.
This macro prints the values of instances given as arguments if the equality
assertion fails so programmers can see why the two instances weren’t equal.

Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/src/ch05-01-defining-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ otherwise use the same values from `user1` that we created in Listing 5-2.
{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-06/src/main.rs:here}}
```

<span class="caption">Listing 5-6: Creating a new `User` instance using one of
<span class="caption">Listing 5-6: Creating a new `User` instance using all but one of
the values from `user1`</span>

Using struct update syntax, we can achieve the same effect with less code, as
Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/src/ch08-01-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ some of the columns in the row contain integers, some floating-point numbers,
and some strings. We can define an enum whose variants will hold the different
value types, and all the enum variants will be considered the same type: that
of the enum. Then we can create a vector to hold that enum and so, ultimately,
holds different types. We’ve demonstrated this in Listing 8-9.
hold different types. We’ve demonstrated this in Listing 8-9.

```rust
{{#rustdoc_include ../listings/ch08-common-collections/listing-08-09/src/main.rs:here}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function, as shown in Listing 12-22. This still won’t compile yet.
Finally, we need to check for the environment variable. The functions for
working with environment variables are in the `env` module in the standard
library, so we bring that module into scope at the top of *src/lib.rs*. Then
we’ll use the `var` function from the `env` module to check to see if any value
we’ll use the `var` function from the `env` module to check if any value
has been set for an environment variable named `IGNORE_CASE`, as shown in
Listing 12-23.

Expand Down
4 changes: 2 additions & 2 deletions rustbook-en/src/ch13-01-closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ compiler won’t let us use this closure with `sort_by_key`:
`sort_by_key`</span>

This is a contrived, convoluted way (that doesn’t work) to try and count the
number of times `sort_by_key` gets called when sorting `list`. This code
number of times `sort_by_key` calls the closure when sorting `list`. This code
attempts to do this counting by pushing `value`—a `String` from the closure’s
environment—into the `sort_operations` vector. The closure captures `value`
then moves `value` out of the closure by transferring ownership of `value` to
Expand All @@ -399,7 +399,7 @@ implement `FnMut`:

The error points to the line in the closure body that moves `value` out of the
environment. To fix this, we need to change the closure body so that it doesn’t
move values out of the environment. To count the number of times `sort_by_key`
move values out of the environment. To count the number of times the closure
is called, keeping a counter in the environment and incrementing its value in
the closure body is a more straightforward way to calculate that. The closure
in Listing 13-9 works with `sort_by_key` because it is only capturing a mutable
Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/src/ch15-02-deref.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ smart pointers to work in ways similar to references. Then we’ll look at
Rust’s *deref coercion* feature and how it lets us work with either references
or smart pointers.

> Note: there’s one big difference between the `MyBox<T>` type we’re about to
> Note: There’s one big difference between the `MyBox<T>` type we’re about to
> build and the real `Box<T>`: our version will not store its data on the heap.
> We are focusing this example on `Deref`, so where the data is actually stored
> is less important than the pointer-like behavior.
Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/src/ch20-02-multithreaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ overloaded if the server receives a lot of requests. If we make a request to
*/sleep*, the server will be able to serve other requests by having another
thread run them.

> Note: if you open */sleep* in multiple browser windows simultaneously, they
> Note: If you open */sleep* in multiple browser windows simultaneously, they
> might load one at a time in 5 second intervals. Some web browsers execute
> multiple instances of the same request sequentially for caching reasons. This
> limitation is not caused by our web server.
Expand Down

0 comments on commit 87a320f

Please sign in to comment.