Merge branch 'master' of github.com:rust-lang-nursery/rust-cookbook

This commit is contained in:
Andrew Gauger 2019-09-19 12:52:40 -07:00
commit f4d63dada2
8 changed files with 27 additions and 22 deletions

View file

@ -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 - [ ] commits are squashed into one and rebased to latest master
- [ ] PR contains correct "fixes #ISSUE_ID" clause to autoclose the issue on PR merge - [ ] 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 - 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` - [ ] link check runs without errors `link-checker ./book`
- [ ] non rendered items are in sorted order (links, reference, identifiers, Cargo.toml) - [ ] 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` - [ ] links to docs.rs have wildcard version `https://docs.rs/tar/*/tar/struct.Entry.html`

View file

@ -89,10 +89,10 @@ To check the spelling of the Rust Cookbook locally, run the following command
from the root of the Cookbook. from the root of the Cookbook.
``` ```
./ci/spellchecker.sh ./ci/spellcheck.sh
# or, if you're using a different locale # 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 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`. 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. 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 [mdbook]: https://github.com/rust-lang-nursery/mdBook
[python]: https://packaging.python.org/tutorials/installing-packages/#install-pip-setuptools-and-wheel [python]: https://packaging.python.org/tutorials/installing-packages/#install-pip-setuptools-and-wheel
[skeptic]: https://github.com/brson/rust-skeptic [skeptic]: https://github.com/brson/rust-skeptic

View file

@ -32,6 +32,7 @@ nalgebra = "0.16.12"
ndarray = "0.12" ndarray = "0.12"
num = "0.2" num = "0.2"
num_cpus = "1.8" num_cpus = "1.8"
percent-encoding = "2.1"
petgraph = "0.4" petgraph = "0.4"
rand = "0.6" rand = "0.6"
rayon = "1.0" rayon = "1.0"
@ -50,7 +51,7 @@ tempfile = "3.1"
threadpool = "1.6" threadpool = "1.6"
toml = "0.4" toml = "0.4"
unicode-segmentation = "1.2.1" unicode-segmentation = "1.2.1"
url = "1.6" url = "2.1"
walkdir = "2.0" walkdir = "2.0"
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]

View file

@ -1,7 +1,7 @@
# A Rust Cookbook   [![Build Status travis]][travis] [![Build Status appveyor]][appveyor] # 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 [Build Status travis]: https://api.travis-ci.com/rust-lang-nursery/rust-cookbook.svg?branch=master
[travis]: https://travis-ci.org/rust-lang-nursery/rust-cookbook [travis]: https://travis-ci.com/rust-lang-nursery/rust-cookbook
[Build Status appveyor]: https://ci.appveyor.com/api/projects/status/k56hklb7puv7c4he?svg=true [Build Status appveyor]: https://ci.appveyor.com/api/projects/status/k56hklb7puv7c4he?svg=true
[appveyor]: https://ci.appveyor.com/project/rust-lang-libs/rust-cookbook [appveyor]: https://ci.appveyor.com/project/rust-lang-libs/rust-cookbook

View file

@ -19,8 +19,7 @@ fn main() {
let password: String = (0..PASSWORD_LEN) let password: String = (0..PASSWORD_LEN)
.map(|_| { .map(|_| {
let idx = rng.gen_range(0, CHARSET.len()); let idx = rng.gen_range(0, CHARSET.len());
// This is safe because `idx` is in range of `CHARSET` CHARSET[idx] as char
char::from(unsafe { *CHARSET.get_unchecked(idx) })
}) })
.collect(); .collect();

View file

@ -42,18 +42,18 @@ use image::{ImageBuffer, Pixel, Rgb};
# let wave = wavelength as f32; # let wave = wavelength as f32;
# #
# let (r, g, b) = match wavelength { # let (r, g, b) = match wavelength {
# 380...439 => ((440. - wave) / (440. - 380.), 0.0, 1.0), # 380..=439 => ((440. - wave) / (440. - 380.), 0.0, 1.0),
# 440...489 => (0.0, (wave - 440.) / (490. - 440.), 1.0), # 440..=489 => (0.0, (wave - 440.) / (490. - 440.), 1.0),
# 490...509 => (0.0, 1.0, (510. - wave) / (510. - 490.)), # 490..=509 => (0.0, 1.0, (510. - wave) / (510. - 490.)),
# 510...579 => ((wave - 510.) / (580. - 510.), 1.0, 0.0), # 510..=579 => ((wave - 510.) / (580. - 510.), 1.0, 0.0),
# 580...644 => (1.0, (645. - wave) / (645. - 580.), 0.0), # 580..=644 => (1.0, (645. - wave) / (645. - 580.), 0.0),
# 645...780 => (1.0, 0.0, 0.0), # 645..=780 => (1.0, 0.0, 0.0),
# _ => (0.0, 0.0, 0.0), # _ => (0.0, 0.0, 0.0),
# }; # };
# #
# let factor = match wavelength { # let factor = match wavelength {
# 380...419 => 0.3 + 0.7 * (wave - 380.) / (420. - 380.), # 380..=419 => 0.3 + 0.7 * (wave - 380.) / (420. - 380.),
# 701...780 => 0.3 + 0.7 * (780. - wave) / (780. - 700.), # 701..=780 => 0.3 + 0.7 * (780. - wave) / (780. - 700.),
# _ => 1.0, # _ => 1.0,
# }; # };
# #

View file

@ -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`]. 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::{Connection, Result};
use rusqlite::NO_PARAMS; use rusqlite::NO_PARAMS;

View file

@ -1,21 +1,24 @@
## Percent-encode a string ## 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`] 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. function.
```rust ```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; 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> { fn main() -> Result<(), Utf8Error> {
let input = "confident, productive systems programming"; 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(); let encoded: String = iter.collect();
assert_eq!(encoded, "confident,%20productive%20systems%20programming"); assert_eq!(encoded, "confident,%20productive%20systems%20programming");