diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7a9abe2..8561e7f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -12,7 +12,7 @@ No worries if anything in these lists is unclear. Just submit the PR and ask awa - [ ] commits are squashed into one and rebased to latest master - [ ] PR contains correct "fixes #ISSUE_ID" clause to autoclose the issue on PR merge - if issue does not exist consider creating it or remove the clause -- [ ] spell check runs without errors `./ci/spellchecker.sh` +- [ ] spell check runs without errors `./ci/spellcheck.sh` - [ ] link check runs without errors `link-checker ./book` - [ ] non rendered items are in sorted order (links, reference, identifiers, Cargo.toml) - [ ] links to docs.rs have wildcard version `https://docs.rs/tar/*/tar/struct.Entry.html` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 94560a9..f3c67e1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,10 +89,10 @@ To check the spelling of the Rust Cookbook locally, run the following command from the root of the Cookbook. ``` -./ci/spellchecker.sh +./ci/spellcheck.sh # or, if you're using a different locale -LANG=en_US.UTF-8 ./ci/spellchecker.sh +LANG=en_US.UTF-8 ./ci/spellcheck.sh ``` If the spell checker finds a misspelled word, you have the opportunity to @@ -100,6 +100,8 @@ correct the spelling mistake with the number keys. If the spelling mistake is erroneous, add the word to the dictionary located in `ci/dictionary.txt`. Pressing `a` or `l` will not add the word to the custom dictionary. +If there are no errors, it will just print the local Aspell version and exit. + [mdbook]: https://github.com/rust-lang-nursery/mdBook [python]: https://packaging.python.org/tutorials/installing-packages/#install-pip-setuptools-and-wheel [skeptic]: https://github.com/brson/rust-skeptic diff --git a/Cargo.toml b/Cargo.toml index c4ee038..971b611 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ nalgebra = "0.16.12" ndarray = "0.12" num = "0.2" num_cpus = "1.8" +percent-encoding = "2.1" petgraph = "0.4" rand = "0.6" rayon = "1.0" @@ -50,7 +51,7 @@ tempfile = "3.1" threadpool = "1.6" toml = "0.4" unicode-segmentation = "1.2.1" -url = "1.6" +url = "2.1" walkdir = "2.0" [target.'cfg(target_os = "linux")'.dependencies] diff --git a/README.md b/README.md index 14756f8..90d2c16 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # A Rust Cookbook   [![Build Status travis]][travis] [![Build Status appveyor]][appveyor] -[Build Status travis]: https://api.travis-ci.org/rust-lang-nursery/rust-cookbook.svg?branch=master -[travis]: https://travis-ci.org/rust-lang-nursery/rust-cookbook +[Build Status travis]: https://api.travis-ci.com/rust-lang-nursery/rust-cookbook.svg?branch=master +[travis]: https://travis-ci.com/rust-lang-nursery/rust-cookbook [Build Status appveyor]: https://ci.appveyor.com/api/projects/status/k56hklb7puv7c4he?svg=true [appveyor]: https://ci.appveyor.com/project/rust-lang-libs/rust-cookbook diff --git a/src/algorithms/randomness/rand-choose.md b/src/algorithms/randomness/rand-choose.md index 8a95c63..acb61fe 100644 --- a/src/algorithms/randomness/rand-choose.md +++ b/src/algorithms/randomness/rand-choose.md @@ -19,8 +19,7 @@ fn main() { let password: String = (0..PASSWORD_LEN) .map(|_| { let idx = rng.gen_range(0, CHARSET.len()); - // This is safe because `idx` is in range of `CHARSET` - char::from(unsafe { *CHARSET.get_unchecked(idx) }) + CHARSET[idx] as char }) .collect(); diff --git a/src/concurrency/thread/threadpool-fractal.md b/src/concurrency/thread/threadpool-fractal.md index 98e65a8..c94d090 100644 --- a/src/concurrency/thread/threadpool-fractal.md +++ b/src/concurrency/thread/threadpool-fractal.md @@ -42,18 +42,18 @@ use image::{ImageBuffer, Pixel, Rgb}; # let wave = wavelength as f32; # # let (r, g, b) = match wavelength { -# 380...439 => ((440. - wave) / (440. - 380.), 0.0, 1.0), -# 440...489 => (0.0, (wave - 440.) / (490. - 440.), 1.0), -# 490...509 => (0.0, 1.0, (510. - wave) / (510. - 490.)), -# 510...579 => ((wave - 510.) / (580. - 510.), 1.0, 0.0), -# 580...644 => (1.0, (645. - wave) / (645. - 580.), 0.0), -# 645...780 => (1.0, 0.0, 0.0), +# 380..=439 => ((440. - wave) / (440. - 380.), 0.0, 1.0), +# 440..=489 => (0.0, (wave - 440.) / (490. - 440.), 1.0), +# 490..=509 => (0.0, 1.0, (510. - wave) / (510. - 490.)), +# 510..=579 => ((wave - 510.) / (580. - 510.), 1.0, 0.0), +# 580..=644 => (1.0, (645. - wave) / (645. - 580.), 0.0), +# 645..=780 => (1.0, 0.0, 0.0), # _ => (0.0, 0.0, 0.0), # }; # # let factor = match wavelength { -# 380...419 => 0.3 + 0.7 * (wave - 380.) / (420. - 380.), -# 701...780 => 0.3 + 0.7 * (780. - wave) / (780. - 700.), +# 380..=419 => 0.3 + 0.7 * (wave - 380.) / (420. - 380.), +# 701..=780 => 0.3 + 0.7 * (780. - wave) / (780. - 700.), # _ => 1.0, # }; # diff --git a/src/database/sqlite/insert_select.md b/src/database/sqlite/insert_select.md index df37d86..f6a8c94 100644 --- a/src/database/sqlite/insert_select.md +++ b/src/database/sqlite/insert_select.md @@ -6,7 +6,7 @@ This recipe inserts data into `cat_colors` and `cats` tables using the [`execute`] method of `Connection`. First, the data is inserted into the `cat_colors` table. After a record for a color is inserted, [`last_insert_rowid`] method of `Connection` is used to get `id` of the last color inserted. This `id` is used while inserting data into the `cats` table. Then, the select query is prepared using the [`prepare`] method which gives a [`statement`] struct. Then, query is executed using [`query_map`] method of [`statement`]. ``` -eextern crate rusqlite; +extern crate rusqlite; use rusqlite::{Connection, Result}; use rusqlite::NO_PARAMS; diff --git a/src/encoding/string/percent-encode.md b/src/encoding/string/percent-encode.md index ec9ffef..7f39058 100644 --- a/src/encoding/string/percent-encode.md +++ b/src/encoding/string/percent-encode.md @@ -1,21 +1,24 @@ ## Percent-encode a string -[![url-badge]][url] [![cat-encoding-badge]][cat-encoding] +[![url-badge]][percent-encoding] [![cat-encoding-badge]][cat-encoding] Encode an input string with [percent-encoding] using the [`utf8_percent_encode`] -function from the `url` crate. Then decode using the [`percent_decode`] +function from the `percent-encoding` crate. Then decode using the [`percent_decode`] function. ```rust -extern crate url; +extern crate percent_encoding; -use url::percent_encoding::{utf8_percent_encode, percent_decode, DEFAULT_ENCODE_SET}; +use percent_encoding::{utf8_percent_encode, percent_decode, AsciiSet, CONTROLS}; use std::str::Utf8Error; +/// https://url.spec.whatwg.org/#fragment-percent-encode-set +const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`'); + fn main() -> Result<(), Utf8Error> { let input = "confident, productive systems programming"; - let iter = utf8_percent_encode(input, DEFAULT_ENCODE_SET); + let iter = utf8_percent_encode(input, FRAGMENT); let encoded: String = iter.collect(); assert_eq!(encoded, "confident,%20productive%20systems%20programming");