Skip to content

Commit 8542f7f

Browse files
tesujiDylan-DPC
authored andcommitted
Transition to 2018 edition (#933)
* Transition to 2018 edition * Update Travis CI badge in README * Remove non-idiomatic `extern crate` lines
1 parent fe492d1 commit 8542f7f

37 files changed

+82
-158
lines changed

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ authors = [
66
"Michael-F-Bryan <[email protected]>",
77
"Matt Ickstadt <[email protected]>"
88
]
9-
description = "Creates a book from markdown files"
109
documentation = "http://rust-lang-nursery.github.io/mdBook/index.html"
11-
repository = "https://github.com/rust-lang-nursery/mdBook"
10+
edition = "2018"
11+
exclude = ["/book-example/*"]
1212
keywords = ["book", "gitbook", "rustbook", "markdown"]
1313
license = "MPL-2.0"
1414
readme = "README.md"
15-
exclude = ["book-example/*"]
15+
repository = "https://github.com/rust-lang-nursery/mdBook"
16+
description = "Creates a book from markdown files"
1617

1718
[dependencies]
1819
clap = "2.24"

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<tr>
55
<td><strong>Linux / OS X</strong></td>
66
<td>
7-
<a href="https://travis-ci.org/rust-lang-nursery/mdBook"><img src="https://travis-ci.org/rust-lang-nursery/mdBook.svg?branch=master"></a>
7+
<a href="https://travis-ci.com/rust-lang-nursery/mdBook"><img src="https://travis-ci.com/rust-lang-nursery/mdBook.svg?branch=master"></a>
88
</td>
99
</tr>
1010
<tr>
@@ -65,7 +65,7 @@ There are multiple ways to install mdBook.
6565
cargo install mdbook --vers "^0.1.0"
6666
```
6767

68-
3. **From Git**
68+
3. **From Git**
6969

7070
The version published to crates.io will ever so slightly be behind the
7171
version hosted here on GitHub. If you need the latest version you can build
@@ -77,7 +77,7 @@ There are multiple ways to install mdBook.
7777

7878
Again, make sure to add the Cargo bin directory to your `PATH`.
7979

80-
4. **For Contributions**
80+
4. **For Contributions**
8181

8282
If you want to contribute to mdBook you will have to clone the repository on
8383
your local machine:
@@ -152,9 +152,9 @@ party plugins. These plugins are just programs which will be invoked during the
152152
build process and are split into roughly two categories, *preprocessors* and
153153
*renderers*.
154154
155-
Preprocessors are used to transform a book before it is sent to a renderer.
156-
One example would be to replace all occurrences of
157-
`{{#include some_file.ext}}` with the contents of that file. Some existing
155+
Preprocessors are used to transform a book before it is sent to a renderer.
156+
One example would be to replace all occurrences of
157+
`{{#include some_file.ext}}` with the contents of that file. Some existing
158158
preprocessors are:
159159
160160
- `index` - a built-in preprocessor (enabled by default) which will transform

examples/de-emphasize.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
//! An example preprocessor for removing all forms of emphasis from a markdown
22
//! book.
3-
4-
extern crate mdbook;
5-
extern crate pulldown_cmark;
6-
extern crate pulldown_cmark_to_cmark;
7-
83
use mdbook::book::{Book, BookItem, Chapter};
94
use mdbook::errors::{Error, Result};
105
use mdbook::preprocess::{Preprocessor, PreprocessorContext};

examples/nop-preprocessor.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
extern crate clap;
2-
extern crate mdbook;
3-
extern crate serde_json;
4-
1+
use crate::nop_lib::Nop;
52
use clap::{App, Arg, ArgMatches, SubCommand};
63
use mdbook::book::Book;
74
use mdbook::errors::Error;
85
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
9-
use nop_lib::Nop;
106
use std::io;
117
use std::process;
128

src/book/book.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::io::{Read, Write};
55
use std::path::{Path, PathBuf};
66

77
use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
8-
use config::BuildConfig;
9-
use errors::*;
8+
use crate::config::BuildConfig;
9+
use crate::errors::*;
1010

1111
/// Load a book into memory from its `src/` directory.
1212
pub fn load_book<P: AsRef<Path>>(src_dir: P, cfg: &BuildConfig) -> Result<Book> {

src/book/init.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::fs::{self, File};
22
use std::io::Write;
33
use std::path::PathBuf;
4-
use toml;
54

65
use super::MDBook;
7-
use config::Config;
8-
use errors::*;
9-
use theme;
6+
use crate::config::Config;
7+
use crate::errors::*;
8+
use crate::theme;
109

1110
/// A helper for setting up a new book and its directory structure.
1211
#[derive(Debug, Clone, PartialEq)]

src/book/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use std::string::ToString;
2020
use tempfile::Builder as TempFileBuilder;
2121
use toml::Value;
2222

23-
use errors::*;
24-
use preprocess::{
23+
use crate::errors::*;
24+
use crate::preprocess::{
2525
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
2626
};
27-
use renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
28-
use utils;
27+
use crate::renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
28+
use crate::utils;
2929

30-
use config::Config;
30+
use crate::config::Config;
3131

3232
/// The object used to manage and build a book.
3333
pub struct MDBook {
@@ -124,7 +124,6 @@ impl MDBook {
124124
/// `(section: String, bookitem: &BookItem)`
125125
///
126126
/// ```no_run
127-
/// # extern crate mdbook;
128127
/// # use mdbook::MDBook;
129128
/// # use mdbook::book::BookItem;
130129
/// # #[allow(unused_variables)]

src/book/summary.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use errors::*;
1+
use crate::errors::*;
22
use memchr::{self, Memchr};
33
use pulldown_cmark::{self, Event, Tag};
44
use std::fmt::{self, Display, Formatter};

src/cmd/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::{get_book_dir, open};
12
use clap::{App, ArgMatches, SubCommand};
23
use mdbook::errors::Result;
34
use mdbook::MDBook;
4-
use {get_book_dir, open};
55

66
// Create clap subcommand arguments
77
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {

src/cmd/clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::get_book_dir;
12
use clap::{App, ArgMatches, SubCommand};
2-
use get_book_dir;
33
use mdbook::errors::*;
44
use mdbook::MDBook;
55
use std::fs;

src/cmd/init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::get_book_dir;
12
use clap::{App, ArgMatches, SubCommand};
2-
use get_book_dir;
33
use mdbook::config;
44
use mdbook::errors::Result;
55
use mdbook::MDBook;

src/cmd/serve.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
extern crate iron;
2-
extern crate staticfile;
3-
extern crate ws;
4-
5-
use self::iron::{
6-
status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set,
7-
};
81
#[cfg(feature = "watch")]
92
use super::watch;
3+
use crate::{get_book_dir, open};
104
use clap::{App, Arg, ArgMatches, SubCommand};
5+
use iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set};
116
use mdbook::errors::*;
127
use mdbook::utils;
138
use mdbook::MDBook;
14-
use std;
15-
use {get_book_dir, open};
169

1710
struct ErrorRecover;
1811

src/cmd/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::get_book_dir;
12
use clap::{App, Arg, ArgMatches, SubCommand};
2-
use get_book_dir;
33
use mdbook::errors::Result;
44
use mdbook::MDBook;
55

src/cmd/watch.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
extern crate notify;
2-
3-
use self::notify::Watcher;
1+
use crate::{get_book_dir, open};
42
use clap::{App, ArgMatches, SubCommand};
53
use mdbook::errors::Result;
64
use mdbook::utils;
75
use mdbook::MDBook;
6+
use notify::Watcher;
87
use std::path::{Path, PathBuf};
98
use std::sync::mpsc::channel;
109
use std::thread::sleep;
1110
use std::time::Duration;
12-
use {get_book_dir, open};
1311

1412
// Create clap subcommand arguments
1513
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
@@ -55,8 +53,8 @@ pub fn trigger_on_change<F>(book: &MDBook, closure: F)
5553
where
5654
F: Fn(Vec<PathBuf>, &Path),
5755
{
58-
use self::notify::DebouncedEvent::*;
59-
use self::notify::RecursiveMode::*;
56+
use notify::DebouncedEvent::*;
57+
use notify::RecursiveMode::*;
6058

6159
// Create a channel to receive the events.
6260
let (tx, rx) = channel();

src/config.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
//! # Examples
1010
//!
1111
//! ```rust
12-
//! # extern crate mdbook;
1312
//! # use mdbook::errors::*;
14-
//! # extern crate toml;
1513
//! use std::path::PathBuf;
1614
//! use std::str::FromStr;
1715
//! use mdbook::Config;
@@ -52,7 +50,6 @@
5250
#![deny(missing_docs)]
5351

5452
use serde::{Deserialize, Deserializer, Serialize, Serializer};
55-
use serde_json;
5653
use std::env;
5754
use std::fs::File;
5855
use std::io::Read;
@@ -64,7 +61,7 @@ use toml_query::delete::TomlValueDeleteExt;
6461
use toml_query::insert::TomlValueInsertExt;
6562
use toml_query::read::TomlValueReadExt;
6663

67-
use errors::*;
64+
use crate::errors::*;
6865

6966
/// The overall configuration object for MDBook, essentially an in-memory
7067
/// representation of `book.toml`.

src/lib.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,14 @@
8585

8686
#[macro_use]
8787
extern crate error_chain;
88-
extern crate handlebars;
89-
extern crate itertools;
9088
#[macro_use]
9189
extern crate lazy_static;
9290
#[macro_use]
9391
extern crate log;
94-
extern crate memchr;
95-
extern crate pulldown_cmark;
96-
extern crate regex;
97-
extern crate serde;
9892
#[macro_use]
9993
extern crate serde_derive;
10094
#[macro_use]
10195
extern crate serde_json;
102-
extern crate shlex;
103-
extern crate tempfile;
104-
extern crate toml;
105-
extern crate toml_query;
10696

10797
#[cfg(test)]
10898
#[macro_use]
@@ -121,10 +111,10 @@ pub mod utils;
121111
/// compatibility checks.
122112
pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION");
123113

124-
pub use book::BookItem;
125-
pub use book::MDBook;
126-
pub use config::Config;
127-
pub use renderer::Renderer;
114+
pub use crate::book::BookItem;
115+
pub use crate::book::MDBook;
116+
pub use crate::config::Config;
117+
pub use crate::renderer::Renderer;
128118

129119
/// The error types used through out this crate.
130120
pub mod errors {

src/main.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
extern crate chrono;
21
#[macro_use]
32
extern crate clap;
4-
extern crate env_logger;
5-
extern crate error_chain;
63
#[macro_use]
74
extern crate log;
8-
extern crate mdbook;
9-
extern crate open;
105

116
use chrono::Local;
127
use clap::{App, AppSettings, ArgMatches};

src/preprocess/cmd.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::{Preprocessor, PreprocessorContext};
2-
use book::Book;
3-
use errors::*;
4-
use serde_json;
2+
use crate::book::Book;
3+
use crate::errors::*;
54
use shlex::Shlex;
65
use std::io::{self, Read, Write};
76
use std::process::{Child, Command, Stdio};
@@ -168,8 +167,8 @@ impl Preprocessor for CmdPreprocessor {
168167
#[cfg(test)]
169168
mod tests {
170169
use super::*;
170+
use crate::MDBook;
171171
use std::path::Path;
172-
use MDBook;
173172

174173
fn book_example() -> MDBook {
175174
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example");

src/preprocess/index.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use regex::Regex;
22
use std::path::Path;
33

4-
use errors::*;
4+
use crate::errors::*;
55

66
use super::{Preprocessor, PreprocessorContext};
7-
use book::{Book, BookItem};
7+
use crate::book::{Book, BookItem};
88

99
/// A preprocessor for converting file name `README.md` to `index.md` since
1010
/// `README.md` is the de facto index file in markdown-based documentation.

src/preprocess/links.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use errors::*;
1+
use crate::errors::*;
2+
use crate::utils::fs::file_to_string;
3+
use crate::utils::take_lines;
24
use regex::{CaptureMatches, Captures, Regex};
35
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
46
use std::path::{Path, PathBuf};
5-
use utils::fs::file_to_string;
6-
use utils::take_lines;
77

88
use super::{Preprocessor, PreprocessorContext};
9-
use book::{Book, BookItem};
9+
use crate::book::{Book, BookItem};
1010

1111
const ESCAPE_CHAR: char = '\\';
1212
const MAX_LINK_NESTED_DEPTH: usize = 10;

src/preprocess/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ mod cmd;
88
mod index;
99
mod links;
1010

11-
use book::Book;
12-
use config::Config;
13-
use errors::*;
11+
use crate::book::Book;
12+
use crate::config::Config;
13+
use crate::errors::*;
1414

1515
use std::path::PathBuf;
1616

@@ -37,7 +37,7 @@ impl PreprocessorContext {
3737
root,
3838
config,
3939
renderer,
40-
mdbook_version: ::MDBOOK_VERSION.to_string(),
40+
mdbook_version: crate::MDBOOK_VERSION.to_string(),
4141
__non_exhaustive: (),
4242
}
4343
}

0 commit comments

Comments
 (0)