Skip to content

Commit 87b43bb

Browse files
committed
Completed review
1 parent 31f463f commit 87b43bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+123
-169
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ cargo test
5151

5252
This project is intended to be simple to contribute to, and to always
5353
have obvious next work items available. If at any time there is not
54-
something obvious to contribute, that is a bug. Please ask for
55-
assistance on the [libz blitz] thread, or email Brian Anderson
56-
directly ([email protected]).
54+
something obvious to contribute, that is a bug. Feel free to ask for
55+
additional support at the
56+
[Rust Ecosystem Working Group](https://gitter.im/rust-lang/WG-ecosystem).
5757

5858
The development process for the cookbook is presently oriented around
5959
crates: we decide which crates to represent in the cookbook, then come
@@ -146,16 +146,18 @@ something a typical Rust user typically wants to do.
146146
#### Description
147147

148148
Describe traits imported and the methods used. Think about what information
149-
supports the use case and might not be obvious to someone new. Keep the
150-
description to 1-4 sentences, avoiding explanations outside the scope of the
149+
supports the use case and might not be obvious to someone new. Keep the
150+
description to 1-4 sentences, avoiding explanations outside the scope of the
151151
code sample.
152152

153-
Use third person narative of the code execution, taking the opportunity
154-
to link to API documentation. Hyperlink all references to APIs, either
153+
Use third person narrative of the code execution, taking the opportunity
154+
to link to API documentation. Always use
155+
[active voice](https://www.plainlanguage.gov/guidelines/conversational/use-active-voice/).
156+
Hyperlink all references to APIs, either
155157
on doc.rust-lang.org/std or docs.rs, and style them as `code`. Use
156158
wildcard version specifiers for crate links.
157159

158-
Any requirements to execute the code that are not apparent, such as
160+
Any requirements to execute the code that are not apparent, such as
159161
passing environment flags, or configuring `Cargo.toml` should be added
160162
after the code sample.
161163

@@ -164,8 +166,8 @@ after the code sample.
164166
> distribution, then sample from that distribution using
165167
> [`Distribution::sample`] with help of a random-number
166168
> generator [`rand::Rng`].
167-
>
168-
> The [distributions available are documented here][rand-distributions].
169+
>
170+
> The [distributions available are documented here][rand-distributions].
169171
> An example using the [`Normal`] distribution is shown below.
170172
171173
[uniform distribution]: https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)
@@ -190,11 +192,11 @@ error handling correctly and propagate errors with `?` (not `try!`, `urwrap`, or
190192
`expect`). If there is no need for error handling in the example, prefer `main()`.
191193

192194
Avoid glob imports (`*`), even for preludes, so that users can see what
193-
traits are called. (Some crates might consider using glob imports for preludes
195+
traits are called. (Some crates might consider using glob imports for preludes
194196
best practice, making this awkward.)
195197

196198
Examples should be simple and obvious enough that an experienced dev
197-
do not need comments.
199+
do not need comments.
198200

199201
Examples should compile without warnings, clippy lint warnings, or panics.
200202
The code should be formatted by rustfmt. Hide all error boilerplate and
@@ -206,9 +208,9 @@ explanation in the description.
206208

207209
> ```rust
208210
> extern crate rand;
209-
>
211+
>
210212
> use rand::distributions::{Normal, Distribution};
211-
>
213+
>
212214
> fn main() {
213215
> let mut rng = rand::thread_rng();
214216
> let normal = Normal::new(2.0, 3.0);

src/cli/arguments/clap-basic.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern crate clap;
1717
use clap::{Arg, App};
1818

1919
fn main() {
20-
// Define command line arguments.
2120
let matches = App::new("My Test Program")
2221
.version("0.1.0")
2322
.author("Hackerman Jones <[email protected]>")
@@ -34,11 +33,9 @@ fn main() {
3433
.help("Five less than your favorite number"))
3534
.get_matches();
3635

37-
// Get value for file, or default to 'input.txt'.
3836
let myfile = matches.value_of("file").unwrap_or("input.txt");
3937
println!("The file passed is: {}", myfile);
4038

41-
// Get value for num if present, and try parsing it as i32.
4239
let num_str = matches.value_of("num");
4340
match num_str {
4441
None => println!("No idea what your favorite number is."),

src/compression/tar/tar-decompress.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ use tar::Archive;
2626
fn run() -> Result<()> {
2727
let path = "archive.tar.gz";
2828
29-
// Open a compressed tarball
3029
let tar_gz = File::open(path)?;
31-
// Decompress it
3230
let tar = GzDecoder::new(tar_gz);
33-
// Load the archive from the tarball
3431
let mut archive = Archive::new(tar);
35-
// Unpack the archive inside curent working directory
3632
archive.unpack(".")?;
3733
3834
Ok(())

src/compression/tar/tar-strip-prefix.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ fn run() -> Result<()> {
3434
.entries()?
3535
.filter_map(|e| e.ok())
3636
.map(|mut entry| -> Result<PathBuf> {
37-
// Need to get owned data to break the borrow loop
3837
let path = entry.path()?.strip_prefix(prefix)?.to_owned();
3938
entry.unpack(&path)?;
4039
Ok(path)

src/concurrency.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
| [Sort a vector in parallel][ex-rayon-parallel-sort] | [![rayon-badge]][rayon] [![rand-badge]][rand] | [![cat-concurrency-badge]][cat-concurrency] |
1313
| [Map-reduce in parallel][ex-rayon-map-reduce] | [![rayon-badge]][rayon] | [![cat-concurrency-badge]][cat-concurrency] |
1414
| [Generate jpg thumbnails in parallel][ex-rayon-thumbnails] | [![rayon-badge]][rayon] [![glob-badge]][glob] [![image-badge]][image] | [![cat-concurrency-badge]][cat-concurrency][![cat-filesystem-badge]][cat-filesystem] |
15-
=======
16-
>>>>>>> 4e55642... merge artifacts removed
1715

1816

1917
[ex-crossbeam-spawn]: concurrency/threads.html#spawn-a-short-lived-thread

src/concurrency/parallel/rayon-any-all.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ use rayon::prelude::*;
1212
fn main() {
1313
let mut vec = vec![2, 4, 6, 8];
1414

15-
assert!(!vec.par_iter().any(|n| (*n % 2) != 0)); // None are odd.
16-
assert!(vec.par_iter().all(|n| (*n % 2) == 0)); // All are even.
17-
assert!(!vec.par_iter().any(|n| *n > 8 )); // None are greater than 8.
18-
assert!(vec.par_iter().all(|n| *n <= 8 )); // All are less than or equal to 8.
15+
assert!(!vec.par_iter().any(|n| (*n % 2) != 0));
16+
assert!(vec.par_iter().all(|n| (*n % 2) == 0));
17+
assert!(!vec.par_iter().any(|n| *n > 8 ));
18+
assert!(vec.par_iter().all(|n| *n <= 8 ));
1919

2020
vec.push(9);
2121

22-
assert!(vec.par_iter().any(|n| (*n % 2) != 0)); // At least 1 is odd.
23-
assert!(!vec.par_iter().all(|n| (*n % 2) == 0)); // Not all are even.
24-
assert!(vec.par_iter().any(|n| *n > 8 )); // At least 1 is greater than 8.
25-
assert!(!vec.par_iter().all(|n| *n <= 8 )); // Not all are less than or equal to 8.
22+
assert!(vec.par_iter().any(|n| (*n % 2) != 0));
23+
assert!(!vec.par_iter().all(|n| (*n % 2) == 0));
24+
assert!(vec.par_iter().any(|n| *n > 8 ));
25+
assert!(!vec.par_iter().all(|n| *n <= 8 ));
2626
}
2727
```
2828

src/concurrency/parallel/rayon-iter-mut.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use rayon::prelude::*;
1313

1414
fn main() {
1515
let mut arr = [0, 7, 9, 11];
16-
1716
arr.par_iter_mut().for_each(|p| *p -= 1);
18-
1917
println!("{:?}", arr);
2018
}
2119
```

src/concurrency/parallel/rayon-thumbnails.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ use rayon::prelude::*;
3232
# }
3333
3434
fn run() -> Result<()> {
35-
// find all files in current directory that have a .jpg extension
36-
// use the default MatchOptions so the search is case insensitive
3735
let options: MatchOptions = Default::default();
3836
let files: Vec<_> = glob_with("*.jpg", &options)?
3937
.filter_map(|x| x.ok())
@@ -63,8 +61,6 @@ fn run() -> Result<()> {
6361
Ok(())
6462
}
6563
66-
/// Resize `original` to have a maximum dimension of `longest_edge` and save the
67-
/// resized image to the `thumb_dir` folder
6864
fn make_thumbnail<PA, PB>(original: PA, thumb_dir: PB, longest_edge: u32) -> Result<()>
6965
where
7066
PA: AsRef<Path>,

src/concurrency/thread/crossbeam-spawn.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fn main() {
2121
}
2222

2323
fn find_max(arr: &[i32], start: usize, end: usize) -> i32 {
24-
// Perform sequential computation if there are only a few elements.
2524
const THRESHOLD: usize = 2;
2625
if end - start <= THRESHOLD {
2726
return *arr.iter().max().unwrap();

src/concurrency/thread/global-mut-state.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,19 @@ lazy_static! {
2424
}
2525

2626
fn insert(fruit: &str) -> Result<()> {
27-
// acquire exclusive access
2827
let mut db = FRUIT.lock().map_err(|_| "Failed to acquire MutexGuard")?;
2928
db.push(fruit.to_string());
3029
Ok(())
31-
// release exclusive access
3230
}
3331

3432
fn run() -> Result<()> {
3533
insert("apple")?;
3634
insert("orange")?;
3735
insert("peach")?;
3836
{
39-
// acquire access
4037
let db = FRUIT.lock().map_err(|_| "Failed to acquire MutexGuard")?;
4138

4239
db.iter().enumerate().for_each(|(i, item)| println!("{}: {}", i, item));
43-
// release access
4440
}
4541
insert("grape")?;
4642
Ok(())

src/concurrency/thread/threadpool-fractal.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ fn run() -> Result<()> {
9393
let mut img = ImageBuffer::new(width, height);
9494
let iterations = 300;
9595
96-
// constants to tweak for appearance
9796
let c = Complex::new(-0.8, 0.156);
9897
9998
let pool = ThreadPool::new(num_cpus::get());

src/concurrency/thread/threadpool-walk.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ fn run() -> Result<()> {
5959
6060
let (tx, rx) = channel();
6161
62-
// Look in the current directory.
6362
for entry in WalkDir::new("/home/user/Downloads")
6463
.follow_links(true)
6564
.into_iter()

src/cryptography/encryption/pbkdf2.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ fn run() -> Result<()> {
3030
const N_ITER: u32 = 100_000;
3131
let rng = rand::SystemRandom::new();
3232

33-
// Generate salt
3433
let mut salt = [0u8; CREDENTIAL_LEN];
3534
rng.fill(&mut salt)?;
3635

37-
// Hash password
3836
let password = "Guess Me If You Can!";
3937
let mut pbkdf2_hash = [0u8; CREDENTIAL_LEN];
4038
pbkdf2::derive(
@@ -47,7 +45,6 @@ fn run() -> Result<()> {
4745
println!("Salt: {}", HEXUPPER.encode(&salt));
4846
println!("PBKDF2 hash: {}", HEXUPPER.encode(&pbkdf2_hash));
4947

50-
// Verify hash with correct password and wrong password
5148
let should_succeed = pbkdf2::verify(
5249
&digest::SHA512,
5350
N_ITER,

src/cryptography/hashing/sha-digest.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ fn run() -> Result<()> {
4848
let reader = BufReader::new(input);
4949
let digest = sha256_digest(reader)?;
5050

51-
// digest.as_ref() provides the digest as a byte slice: &[u8]
5251
println!("SHA-256 digest is {}", HEXUPPER.encode(digest.as_ref()));
5352

5453
Ok(())

src/data_structures/custom/bitfield.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ bitflags! {
2525

2626
impl MyFlags {
2727
pub fn clear(&mut self) -> &mut MyFlags {
28-
self.bits = 0; // The `bits` field can be accessed from within the
29-
// same module where the `bitflags!` macro was invoked.
28+
self.bits = 0;
3029
self
3130
}
3231
}
@@ -40,15 +39,14 @@ impl fmt::Display for MyFlags {
4039
fn main() {
4140
let e1 = MyFlags::FLAG_A | MyFlags::FLAG_C;
4241
let e2 = MyFlags::FLAG_B | MyFlags::FLAG_C;
43-
assert_eq!((e1 | e2), MyFlags::FLAG_ABC); // union
44-
assert_eq!((e1 & e2), MyFlags::FLAG_C); // intersection
45-
assert_eq!((e1 - e2), MyFlags::FLAG_A); // set difference
46-
assert_eq!(!e2, MyFlags::FLAG_A); // set complement
42+
assert_eq!((e1 | e2), MyFlags::FLAG_ABC);
43+
assert_eq!((e1 & e2), MyFlags::FLAG_C);
44+
assert_eq!((e1 - e2), MyFlags::FLAG_A);
45+
assert_eq!(!e2, MyFlags::FLAG_A);
4746

4847
let mut flags = MyFlags::FLAG_ABC;
4948
assert_eq!(format!("{}", flags), "00000000000000000000000000000111");
5049
assert_eq!(format!("{}", flags.clear()), "00000000000000000000000000000000");
51-
// Debug trait is automatically derived for the MyFlags through `bitflags!`
5250
assert_eq!(format!("{:?}", MyFlags::FLAG_B), "FLAG_B");
5351
assert_eq!(format!("{:?}", MyFlags::FLAG_A | MyFlags::FLAG_B), "FLAG_A | FLAG_B");
5452
}

src/file/dir/duplicate-name.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,14 @@ use std::collections::HashMap;
1212
use walkdir::WalkDir;
1313
1414
fn main() {
15-
// Counters indexed by filenames
1615
let mut filenames = HashMap::new();
1716
18-
// List recusively all files in the current directory filtering out
19-
// directories and files not accessible (permission denied)
2017
for entry in WalkDir::new(".")
2118
.into_iter()
2219
.filter_map(Result::ok)
2320
.filter(|e| !e.file_type().is_dir()) {
24-
// Get entry's filename
2521
let f_name = String::from(entry.file_name().to_string_lossy());
26-
// Get or initialize the counter
2722
let counter = filenames.entry(f_name.clone()).or_insert(0);
28-
// Update the counter
2923
*counter += 1;
3024
3125
if *counter == 2 {

src/file/dir/find-file.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ use walkdir::WalkDir;
2222
# }
2323
2424
fn run() -> Result<()> {
25-
// List recusively all accessible files in the current directory
2625
for entry in WalkDir::new(".")
2726
.follow_links(true)
2827
.into_iter()
2928
.filter_map(|e| e.ok()) {
30-
// Get entry's filename
3129
let f_name = entry.file_name().to_string_lossy();
32-
// Get entry's modified time
3330
let sec = entry.metadata()?.modified()?;
3431
35-
// Print JSON files modified within the last day
3632
if f_name.ends_with(".json") && sec.elapsed()?.as_secs() < 86400 {
3733
println!("{}", f_name);
3834
}

src/file/dir/loops.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::io;
1717
use std::path::{Path, PathBuf};
1818
use same_file::is_same_file;
1919
20-
// Check this path against all of its parents
2120
fn contains_loop<P: AsRef<Path>>(path: P) -> io::Result<Option<(PathBuf, PathBuf)>> {
2221
let path = path.as_ref();
2322
let mut path_buf = path.to_path_buf();

src/file/dir/png.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Recursively find all PNG files in the current directory.
66
In this case, the `**` pattern matches the current directory and all subdirectories.
77

8-
You can also use the `**` pattern for any directory, not just the current one.
9-
For example, `/media/**/*.png` would match all PNGs in `media` and it's subdirectories.
8+
Use the `**` pattern in any path portion. For example, `/media/**/*.png`
9+
matches all PNGs in `media` and it's subdirectories.
1010

1111
```rust,no_run
1212
# #[macro_use]

src/file/dir/sizes.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
[![walkdir-badge]][walkdir] [![cat-filesystem-badge]][cat-filesystem]
44

55
Recursion depth can be flexibly set by [`WalkDir::min_depth`] & [`WalkDir::max_depth`] methods.
6-
In this example we sum all file sizes to 3 subfolders depth, ignoring files in the root folder
7-
at the same time.
6+
Calculates sum of all file sizes to 3 subfolders depth, ignoring files in the root folder.
87

98
```rust
109
extern crate walkdir;
@@ -16,10 +15,10 @@ fn main() {
1615
.min_depth(1)
1716
.max_depth(3)
1817
.into_iter()
19-
.filter_map(|entry| entry.ok()) // Files, we have access to
20-
.filter_map(|entry| entry.metadata().ok()) // Get metadata
21-
.filter(|metadata| metadata.is_file()) // Filter out directories
22-
.fold(0, |acc, m| acc + m.len()); // Accumulate sizes
18+
.filter_map(|entry| entry.ok())
19+
.filter_map(|entry| entry.metadata().ok())
20+
.filter(|metadata| metadata.is_file())
21+
.fold(0, |acc, m| acc + m.len());
2322

2423
println!("Total size: {} bytes.", total_size);
2524
}

src/file/dir/skip-dot.md

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

33
[![walkdir-badge]][walkdir] [![cat-filesystem-badge]][cat-filesystem]
44

5-
Uses [`filter_entry`] to descend recursively into entries passing the `is_not_hidden` predicate thus skipping hidden files and directories whereas [`Iterator::filter`] would be applied to each [`WalkDir::DirEntry`] even if the parent is a hidden directory.
5+
Uses [`filter_entry`] to descend recursively into entries passing the
6+
`is_not_hidden` predicate thus skipping hidden files and directories.
7+
[`Iterator::filter`] applies to each [`WalkDir::DirEntry`] even if the parent
8+
is a hidden directory.
69

7-
Root dir `"."` is yielded due to [`WalkDir::depth`] usage in `is_not_hidden` predicate.
10+
Root dir `"."` yields through [`WalkDir::depth`] usage in `is_not_hidden`
11+
predicate.
812

913
```rust,no_run
1014
extern crate walkdir;

src/file/read-write/memmap.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ fn run() -> Result<()> {
3333

3434
let random_indexes = [0, 1, 2, 19, 22, 10, 11, 29];
3535
assert_eq!(&map[3..13], b"hovercraft");
36-
// I'm using an iterator here to change indexes to bytes
3736
let random_bytes: Vec<u8> = random_indexes.iter()
3837
.map(|&idx| map[idx])
3938
.collect();

0 commit comments

Comments
 (0)