Skip to content

Commit b61c8e5

Browse files
pickfireAndyGauge
andauthored
Update to edition 2018 (#565)
* Update to edition 2018 Update mdbook to 0.3.5 Command: sed -i '/extern crate/ {N;s/\n$//}' src/**.md; sed -i 's/extern crate error_chain;/use error_chain::error_chain;/; s/extern crate lazy_static;/use lazy_static::lazy_static;/; s/extern crate bitflags;/use bitflags::bitflags;/; s/extern crate serde_json;/ use serde_json::json;/; s/extern crate serde_derive;/use serde::{Serialize, Deserialize};/; /macro_use/d; /extern crate/ d; s/```rust/```rust,edition2018/; s/bail!/error_chain::&/; s/\(debug\|info\|warn\|error\)!/log::&/;' src/**.md Fix #530 * Update rand-dist.md * Fixes #569 * dump syslog version 4 depends on error-chain v 0.11 and version 5 depends on v 0.12 !!!! Co-authored-by: Andrew Gauger <[email protected]>
1 parent 7a06c79 commit b61c8e5

File tree

145 files changed

+256
-809
lines changed

Some content is hidden

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

145 files changed

+256
-809
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cd rust-cookbook
2020
Cookbook is built with [mdBook], so install that first with Cargo:
2121

2222
```
23-
cargo install --version 0.1.8 mdbook
23+
cargo install --version 0.3.5 mdbook
2424
```
2525

2626
To build and view the cookbook locally, run:

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
name = "rust-cookbook"
33
version = "0.1.0"
44
authors = ["Brian Anderson <[email protected]>"]
5+
edition = "2018"
56
license = "MIT/Apache-2.0"
67
publish = false
78

89
build = "build.rs"
910

1011
[dependencies]
1112
ansi_term = "0.11.0"
13+
approx = "0.3"
1214
base64 = "0.9"
1315
bitflags = "1.0"
1416
byteorder = "1.0"
@@ -58,7 +60,7 @@ url = "2.1"
5860
walkdir = "2.0"
5961

6062
[target.'cfg(target_os = "linux")'.dependencies]
61-
syslog = "4.0"
63+
syslog = "5.0"
6264

6365
[build-dependencies]
6466
skeptic = "0.13"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you'd like to read it locally:
1919
```bash
2020
$ git clone https://github.com/rust-lang-nursery/rust-cookbook
2121
$ cd rust-cookbook
22-
$ cargo install mdbook --vers "0.1.8"
22+
$ cargo install mdbook --vers "0.3.5"
2323
$ mdbook serve --open
2424
```
2525

book.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
title = "Rust Cookbook"
44
description = "Collection of useful Rust code examples"
55
authors = ["Rust Language Community"]
6+
edition = "2018"
67
multilingual = false
8+
language = "en"
79
src = "src"
810

911
[output.html]
1012
mathjax-support = false
11-
theme = "theme"
13+
# theme = "theme"
1214
additional-css = ["theme/custom.css"]
1315

1416
[output.html.playpen]

ci/install_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [[ "${CONTENT_TESTS:-}" == 1 ]]; then
1818
pyenv local 3.6.0
1919
pip3 install --user link-checker==0.1.0
2020
fi
21-
cargo install mdbook --vers '0.1.8' --debug
21+
cargo install mdbook --vers '0.3.5' --debug
2222
fi
2323

2424
exit 0

src/about.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ Consider this example for "generate random numbers within a range":
5656

5757
[![rand-badge]][rand] [![cat-science-badge]][cat-science]
5858

59-
```rust
60-
extern crate rand;
59+
```rust,edition2018
6160
use rand::Rng;
6261
6362
fn main() {
@@ -111,10 +110,8 @@ The basic pattern we use is to have a `fn main() -> Result`.
111110

112111
The structure generally looks like:
113112

114-
```rust
115-
#[macro_use]
116-
extern crate error_chain;
117-
113+
```rust,edition2018
114+
use error_chain::error_chain;
118115
use std::net::IpAddr;
119116
use std::str;
120117
@@ -150,10 +147,8 @@ default like below. In order to read full contents click on the
150147
"expand" (<i class="fa fa-expand"></i>) button located in the top
151148
right corner of the snippet.
152149

153-
```rust
154-
# #[macro_use]
155-
# extern crate error_chain;
156-
extern crate url;
150+
```rust,edition2018
151+
# use error_chain::error_chain;
157152
158153
use url::{Url, Position};
159154
#

src/algorithms/randomness/rand-choose.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
Randomly generates a string of given length ASCII characters with custom
66
user-defined bytestring, with [`gen_range`].
77

8-
```rust
9-
extern crate rand;
10-
8+
```rust,edition2018
119
fn main() {
1210
use rand::Rng;
1311
const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\

src/algorithms/randomness/rand-custom.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
Randomly generates a tuple `(i32, bool, f64)` and variable of user defined type `Point`.
66
Implements the [`Distribution`] trait on type Point for [`Standard`] in order to allow random generation.
77

8-
```rust,ignore
9-
extern crate rand;
10-
8+
```rust,edition2018,ignore
119
use rand::Rng;
1210
use rand::distributions::{Distribution, Standard};
1311

src/algorithms/randomness/rand-dist.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ generator [`rand::Rng`].
1212
The [distributions available are documented here][rand-distributions].
1313
An example using the [`Normal`] distribution is shown below.
1414

15-
```rust,ignore
16-
extern crate rand_distr;
17-
extern crate rand;
18-
15+
```rust,edition2018,ignore
1916
use rand_distr::{Distribution, Normal, NormalError};
2017
2118
fn main() -> Result<(), NormalError> {

src/algorithms/randomness/rand-passwd.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
Randomly generates a string of given length ASCII characters in the range `A-Z,
66
a-z, 0-9`, with [`Alphanumeric`] sample.
77

8-
```rust,ignore
9-
extern crate rand;
10-
8+
```rust,edition2018,ignore
119
use rand::{thread_rng, Rng};
1210
use rand::distributions::Alphanumeric;
1311

src/algorithms/randomness/rand-range.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
Generates a random value within half-open `[0, 10)` range (not including `10`) with [`Rng::gen_range`].
66

7-
```rust,ignore
8-
extern crate rand;
9-
7+
```rust,edition2018,ignore
108
use rand::Rng;
119
1210
fn main() {
@@ -20,9 +18,7 @@ fn main() {
2018
This has the same effect, but may be faster when repeatedly generating numbers
2119
in the same range.
2220

23-
```rust,ignore
24-
extern crate rand;
25-
21+
```rust,edition2018,ignore
2622
2723
use rand::distributions::{Distribution, Uniform};
2824

src/algorithms/randomness/rand.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ initialized generator. Integers are uniformly distributed over the range of the
88
type, and floating point numbers are uniformly distributed from 0 up to but not
99
including 1.
1010

11-
```rust
12-
extern crate rand;
13-
11+
```rust,edition2018
1412
use rand::Rng;
1513
1614
fn main() {

src/algorithms/sorting/sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This example sorts a Vector of integers via [`vec::sort`]. Alternative would
66
be to use [`vec::sort_unstable`] which can be faster, but does not preserve
77
the order of equal elements.
88

9-
```rust
9+
```rust,edition2018
1010
fn main() {
1111
let mut vec = vec![1, 5, 10, 2, 15];
1212

src/algorithms/sorting/sort_float.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
A Vector of f32 or f64 can be sorted with [`vec::sort_by`] and [`PartialOrd::partial_cmp`].
66

7-
```rust
7+
```rust,edition2018
88
fn main() {
99
let mut vec = vec![1.1, 1.15, 5.5, 1.123, 2.0];
1010

src/algorithms/sorting/sort_struct.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ order (By name and age). In order to make Person sortable you need four traits [
77
[`PartialEq`], [`Ord`] and [`PartialOrd`]. These traits can be simply derived.
88
You can also provide a custom comparator function using a [`vec:sort_by`] method and sort only by age.
99

10-
```rust
10+
```rust,edition2018
1111
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
1212
struct Person {
1313
name: String,

src/cli/ansi_terminal/ansi_term-basic.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ There are two main data structures in [`ansi_term`]: [`ANSIString`] and [`Style`
1010

1111
### Printing colored text to the Terminal
1212

13-
```rust
14-
extern crate ansi_term;
15-
13+
```rust,edition2018
1614
use ansi_term::Colour;
1715
1816
fn main() {
@@ -29,9 +27,7 @@ For anything more complex than plain foreground colour changes, the code
2927
needs to construct `Style` struct. [`Style::new()`] creates the struct,
3028
and properties chained.
3129

32-
```rust
33-
extern crate ansi_term;
34-
30+
```rust,edition2018
3531
use ansi_term::Style;
3632
3733
fn main() {
@@ -43,9 +39,7 @@ fn main() {
4339

4440
`Colour` implements many similar functions as `Style` and can chain methods.
4541

46-
```rust
47-
extern crate ansi_term;
48-
42+
```rust,edition2018
4943
use ansi_term::Colour;
5044
use ansi_term::Style;
5145

src/cli/arguments/clap-basic.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use to retrieve the value passed. The `short` and `long` options control the
1111
flag the user will be expected to type; short flags look like `-f` and long
1212
flags look like `--file`.
1313

14-
```rust
15-
extern crate clap;
16-
14+
```rust,edition2018
1715
use clap::{Arg, App};
1816
1917
fn main() {

src/compression/tar/tar-compress.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ under `backup/logs`path with [`Builder::append_dir_all`].
1010
[`GzEncoder`] is responsible for transparently compressing the
1111
data prior to writing it into `archive.tar.gz`.
1212

13-
```rust,no_run
14-
extern crate tar;
15-
extern crate flate2;
13+
```rust,edition2018,no_run
1614
1715
use std::fs::File;
1816
use flate2::Compression;

src/compression/tar/tar-decompress.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ extract ([`Archive::unpack`]) all files from a compressed tarball
77
named `archive.tar.gz` located in the current working directory
88
to the same location.
99

10-
```rust,no_run
11-
extern crate flate2;
12-
extern crate tar;
10+
```rust,edition2018,no_run
1311
1412
use std::fs::File;
1513
use flate2::read::GzDecoder;

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ Iterate over the [`Archive::entries`]. Use [`Path::strip_prefix`] to remove
66
the specified path prefix (`bundle/logs`). Finally, extract the [`tar::Entry`]
77
via [`Entry::unpack`].
88

9-
```rust,no_run
10-
# #[macro_use]
11-
# extern crate error_chain;
12-
extern crate flate2;
13-
extern crate tar;
14-
9+
```rust,edition2018,no_run
10+
# use error_chain::error_chain;
1511
use std::fs::File;
1612
use std::path::PathBuf;
1713
use flate2::read::GzDecoder;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
This example demonstrates using the [`rayon::any`] and [`rayon::all`] methods, which are parallelized counterparts to [`std::any`] and [`std::all`]. [`rayon::any`] checks in parallel whether any element of the iterator matches the predicate, and returns as soon as one is found. [`rayon::all`] checks in parallel whether all elements of the iterator match the predicate, and returns as soon as a non-matching element is found.
66

7-
```rust
8-
extern crate rayon;
9-
7+
```rust,edition2018
108
use rayon::prelude::*;
119
1210
fn main() {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ The example uses the `rayon` crate, which is a data parallelism library for Rust
66
`rayon` provides the [`par_iter_mut`] method for any parallel iterable data type.
77
This is an iterator-like chain that potentially executes in parallel.
88

9-
```rust
10-
extern crate rayon;
11-
9+
```rust,edition2018
1210
use rayon::prelude::*;
1311
1412
fn main() {

src/concurrency/parallel/rayon-map-reduce.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ new iteration, and [`rayon::reduce`] performs an operation given the previous
1111
reduction and the current element. Also shows use of [`rayon::sum`],
1212
which has the same result as the reduce operation in this example.
1313

14-
```rust
15-
extern crate rayon;
16-
14+
```rust,edition2018
1715
use rayon::prelude::*;
1816
1917
struct Person {

src/concurrency/parallel/rayon-parallel-search.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ necessarily the first one.
1212
Also note that the argument to the closure is a reference to a reference
1313
(`&&x`). See the discussion on [`std::find`] for additional details.
1414

15-
```rust
16-
extern crate rayon;
17-
15+
```rust,edition2018
1816
use rayon::prelude::*;
1917
2018
fn main() {

src/concurrency/parallel/rayon-parallel-sort.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ values in parallel. Although [multiple options]
99
exist to sort an enumerable data type, [`par_sort_unstable`]
1010
is usually faster than [stable sorting] algorithms.
1111

12-
```rust,ignore
13-
extern crate rand;
14-
extern crate rayon;
12+
```rust,edition2018,ignore
1513
1614
use rand::{Rng, thread_rng};
1715
use rand::distributions::Alphanumeric;

src/concurrency/parallel/rayon-thumbnails.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ then saves them in a new folder called `thumbnails`.
88
[`glob::glob_with`] finds jpeg files in current directory. `rayon` resizes
99
images in parallel using [`par_iter`] calling [`DynamicImage::resize`].
1010

11-
```rust,no_run
12-
# #[macro_use]
13-
# extern crate error_chain;
14-
extern crate glob;
15-
extern crate image;
16-
extern crate rayon;
11+
```rust,edition2018,no_run
12+
# use error_chain::error_chain;
1713
1814
use std::path::Path;
1915
use std::fs::create_dir_all;
@@ -38,7 +34,7 @@ fn main() -> Result<()> {
3834
.collect();
3935
4036
if files.len() == 0 {
41-
bail!("No .jpg files found in current directory");
37+
error_chain::bail!("No .jpg files found in current directory");
4238
}
4339
4440
let thumb_dir = "thumbnails";

src/concurrency/thread/crossbeam-spawn.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ you can reference data from the calling function.
99

1010
This example splits the array in half and performs the work in separate threads.
1111

12-
```rust
13-
extern crate crossbeam;
14-
12+
```rust,edition2018
1513
fn main() {
1614
let arr = &[1, 25, -4, 10];
1715
let max = find_max(arr);

src/concurrency/thread/crossbeam-spsc.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ exchanged between the two threads using a [`crossbeam_channel::unbounded`]
99
channel, meaning there is no limit to the number of storeable messages. The
1010
producer thread sleeps for half a second in between messages.
1111

12-
```rust
13-
extern crate crossbeam;
14-
extern crate crossbeam_channel;
12+
```rust,edition2018
1513
1614
use std::{thread, time};
1715
use crossbeam_channel::unbounded;

0 commit comments

Comments
 (0)