Skip to content

Commit 39d973c

Browse files
committed
update original
1 parent f27a8fa commit 39d973c

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

rust-cookbook/src/algorithms/sorting/sort_struct.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ struct Person {
1515
}
1616
1717
impl Person {
18-
pub fn new(name: String, age: u32) -> Self {
18+
pub fn new(name: &str, age: u32) -> Self {
1919
Person {
20-
name,
20+
name: name.to_string(),
2121
age
2222
}
2323
}
2424
}
2525
2626
fn main() {
2727
let mut people = vec![
28-
Person::new("Zoe".to_string(), 25),
29-
Person::new("Al".to_string(), 60),
30-
Person::new("John".to_string(), 1),
28+
Person::new("Zoe", 25),
29+
Person::new("Al", 60),
30+
Person::new("John", 1),
3131
];
3232
3333
// Sort people by derived natural order (Name and age)
@@ -36,9 +36,9 @@ fn main() {
3636
assert_eq!(
3737
people,
3838
vec![
39-
Person::new("Al".to_string(), 60),
40-
Person::new("John".to_string(), 1),
41-
Person::new("Zoe".to_string(), 25),
39+
Person::new("Al", 60),
40+
Person::new("John", 1),
41+
Person::new("Zoe", 25),
4242
]);
4343
4444
// Sort people by age
@@ -47,9 +47,9 @@ fn main() {
4747
assert_eq!(
4848
people,
4949
vec![
50-
Person::new("Al".to_string(), 60),
51-
Person::new("Zoe".to_string(), 25),
52-
Person::new("John".to_string(), 1),
50+
Person::new("Al", 60),
51+
Person::new("Zoe", 25),
52+
Person::new("John", 1),
5353
]);
5454
5555
}

rust-cookbook/src/encoding/csv/delimiter.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ struct Record {
1818
use csv::ReaderBuilder;
1919
2020
fn main() -> Result<(), Error> {
21-
let data = "name\tplace\tid
22-
Mark\tMelbourne\t46
23-
Ashley\tZurich\t92";
21+
let data = "name\tplace\tid\n\
22+
Mark\tMelbourne\t46\n\
23+
Ashley\tZurich\t92";
2424
2525
let mut reader = ReaderBuilder::new().delimiter(b'\t').from_reader(data.as_bytes());
2626
for result in reader.deserialize::<Record>() {

rust-cookbook/src/encoding/string/percent-encode.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![percent-encoding-badge]][percent-encoding] [![cat-encoding-badge]][cat-encoding]
44

5-
Encode an input string with [percent-encoding] using the [`utf8_percent_encode`]
6-
function from the `percent-encoding` crate. Then decode using the [`percent_decode`]
7-
function.
5+
Encode an input string with [percent-encoding][percent-encoding-wiki] using the
6+
[`utf8_percent_encode`] function from the `percent-encoding` crate. Then decode
7+
using the [`percent_decode`] function.
88

99
```rust,edition2018
1010
use percent_encoding::{utf8_percent_encode, percent_decode, AsciiSet, CONTROLS};
@@ -38,4 +38,5 @@ a `String`.
3838
[`percent_decode`]: https://docs.rs/percent-encoding/*/percent_encoding/fn.percent_decode.html
3939
[`utf8_percent_encode`]: https://docs.rs/percent-encoding/*/percent_encoding/fn.utf8_percent_encode.html
4040

41-
[percent-encoding]: https://en.wikipedia.org/wiki/Percent-encoding
41+
[percent-encoding]: https://docs.rs/percent-encoding/
42+
[percent-encoding-wiki]: https://en.wikipedia.org/wiki/Percent-encoding

rust-cookbook/src/science/mathematics/trigonometry/side-length.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
[![std-badge]][std] [![cat-science-badge]][cat-science]
44

5-
Calculates the length of the hypotenuse of a right-angle triangle with an angle of 2 radians and opposite side length of 80.
5+
Calculates the length of the hypotenuse of a right-angle triangle with an angle of 1 radian and opposite side length of 80.
66

77
```rust,edition2018
88
fn main() {
9-
let angle: f64 = 2.0;
9+
let angle: f64 = 1.0;
1010
let side_length = 80.0;
1111
1212
let hypotenuse = side_length / angle.sin();

rust-cookbook/src/web/clients/download/basic.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Creates a temporary directory with [`tempfile::Builder`] and downloads
66
a file over HTTP using [`reqwest::get`] asynchronously.
77

88
Creates a target [`File`] with name obtained from [`Response::url`] within
9-
[`tempdir()`] and copies downloaded data into it with [`io::copy`].
9+
[`tempdir()`] and writes downloaded data into it with [`Writer::write_all`].
1010
The temporary directory is automatically removed on program exit.
1111

1212
```rust,edition2018,no_run
1313
use error_chain::error_chain;
14-
use std::io::copy;
14+
use std::io::Write;
1515
use std::fs::File;
1616
use tempfile::Builder;
1717
@@ -41,15 +41,15 @@ async fn main() -> Result<()> {
4141
println!("will be located under: '{:?}'", fname);
4242
File::create(fname)?
4343
};
44-
let content = response.text().await?;
45-
copy(&mut content.as_bytes(), &mut dest)?;
44+
let content = response.bytes().await?;
45+
dest.write_all(&content)?;
4646
Ok(())
4747
}
4848
```
4949

5050
[`File`]: https://doc.rust-lang.org/std/fs/struct.File.html
51-
[`io::copy`]: https://doc.rust-lang.org/std/io/fn.copy.html
5251
[`reqwest::get`]: https://docs.rs/reqwest/*/reqwest/fn.get.html
5352
[`Response::url`]: https://docs.rs/reqwest/*/reqwest/struct.Response.html#method.url
5453
[`tempfile::Builder`]: https://docs.rs/tempfile/*/tempfile/struct.Builder.html
55-
[`tempdir()`]: https://docs.rs/tempfile/3.1.0/tempfile/struct.Builder.html#method.tempdir
54+
[`tempdir()`]: https://docs.rs/tempfile/*/tempfile/struct.Builder.html#method.tempdir
55+
[`Writer::write_all`]: https://doc.rust-lang.org/std/io/trait.Write.html#method.write_all

rust-cookbook/src/web/clients/download/partial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Uses [`reqwest::blocking::Client::head`] to get the [Content-Length] of the response.
66

77
The code then uses [`reqwest::blocking::Client::get`] to download the content in
8-
chunks of 10240 bytes, while printing progress messages. This exmple uses the synchronous
8+
chunks of 10240 bytes, while printing progress messages. This example uses the synchronous
99
reqwest module. The [Range] header specifies the chunk size and position.
1010

1111
The Range header is defined in [RFC7233][HTTP Range RFC7233].

0 commit comments

Comments
 (0)