summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlzutao <taolzu@gmail.com>2019-05-26 01:50:41 +0700
committerDylan DPC <dylan.dpc@gmail.com>2019-05-25 20:50:41 +0200
commit8542f7f29d2f84f2c1dc91d17c87501563b56879 (patch)
tree5e6b4e2ee74258eca93099e862cf5ac605994c14 /src
parentfe492d1cb9262951e378d87a35ca1927d938ee91 (diff)
Transition to 2018 edition (#933)
* Transition to 2018 edition * Update Travis CI badge in README * Remove non-idiomatic `extern crate` lines
Diffstat (limited to 'src')
-rw-r--r--src/book/book.rs4
-rw-r--r--src/book/init.rs7
-rw-r--r--src/book/mod.rs11
-rw-r--r--src/book/summary.rs2
-rw-r--r--src/cmd/build.rs2
-rw-r--r--src/cmd/clean.rs2
-rw-r--r--src/cmd/init.rs2
-rw-r--r--src/cmd/serve.rs11
-rw-r--r--src/cmd/test.rs2
-rw-r--r--src/cmd/watch.rs10
-rw-r--r--src/config.rs5
-rw-r--r--src/lib.rs18
-rw-r--r--src/main.rs5
-rw-r--r--src/preprocess/cmd.rs7
-rw-r--r--src/preprocess/index.rs4
-rw-r--r--src/preprocess/links.rs8
-rw-r--r--src/preprocess/mod.rs8
-rw-r--r--src/renderer/html_handlebars/hbs_renderer.rs17
-rw-r--r--src/renderer/html_handlebars/helpers/navigation.rs3
-rw-r--r--src/renderer/html_handlebars/helpers/toc.rs3
-rw-r--r--src/renderer/html_handlebars/search.rs18
-rw-r--r--src/renderer/mod.rs9
-rw-r--r--src/theme/mod.rs2
-rw-r--r--src/utils/fs.rs6
-rw-r--r--src/utils/mod.rs2
25 files changed, 63 insertions, 105 deletions
diff --git a/src/book/book.rs b/src/book/book.rs
index f4870f1f..6a31c9e8 100644
--- a/src/book/book.rs
+++ b/src/book/book.rs
@@ -5,8 +5,8 @@ use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
-use config::BuildConfig;
-use errors::*;
+use crate::config::BuildConfig;
+use crate::errors::*;
/// Load a book into memory from its `src/` directory.
pub fn load_book<P: AsRef<Path>>(src_dir: P, cfg: &BuildConfig) -> Result<Book> {
diff --git a/src/book/init.rs b/src/book/init.rs
index a70006bb..f940e1fa 100644
--- a/src/book/init.rs
+++ b/src/book/init.rs
@@ -1,12 +1,11 @@
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
-use toml;
use super::MDBook;
-use config::Config;
-use errors::*;
-use theme;
+use crate::config::Config;
+use crate::errors::*;
+use crate::theme;
/// A helper for setting up a new book and its directory structure.
#[derive(Debug, Clone, PartialEq)]
diff --git a/src/book/mod.rs b/src/book/mod.rs
index 040e7265..3b25c68e 100644
--- a/src/book/mod.rs
+++ b/src/book/mod.rs
@@ -20,14 +20,14 @@ use std::string::ToString;
use tempfile::Builder as TempFileBuilder;
use toml::Value;
-use errors::*;
-use preprocess::{
+use crate::errors::*;
+use crate::preprocess::{
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
};
-use renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
-use utils;
+use crate::renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
+use crate::utils;
-use config::Config;
+use crate::config::Config;
/// The object used to manage and build a book.
pub struct MDBook {
@@ -124,7 +124,6 @@ impl MDBook {
/// `(section: String, bookitem: &BookItem)`
///
/// ```no_run
- /// # extern crate mdbook;
/// # use mdbook::MDBook;
/// # use mdbook::book::BookItem;
/// # #[allow(unused_variables)]
diff --git a/src/book/summary.rs b/src/book/summary.rs
index e61a3459..2c32cbd8 100644
--- a/src/book/summary.rs
+++ b/src/book/summary.rs
@@ -1,4 +1,4 @@
-use errors::*;
+use crate::errors::*;
use memchr::{self, Memchr};
use pulldown_cmark::{self, Event, Tag};
use std::fmt::{self, Display, Formatter};
diff --git a/src/cmd/build.rs b/src/cmd/build.rs
index da42015e..d1c66302 100644
--- a/src/cmd/build.rs
+++ b/src/cmd/build.rs
@@ -1,7 +1,7 @@
+use crate::{get_book_dir, open};
use clap::{App, ArgMatches, SubCommand};
use mdbook::errors::Result;
use mdbook::MDBook;
-use {get_book_dir, open};
// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
diff --git a/src/cmd/clean.rs b/src/cmd/clean.rs
index 5045dc74..420037d7 100644
--- a/src/cmd/clean.rs
+++ b/src/cmd/clean.rs
@@ -1,5 +1,5 @@
+use crate::get_book_dir;
use clap::{App, ArgMatches, SubCommand};
-use get_book_dir;
use mdbook::errors::*;
use mdbook::MDBook;
use std::fs;
diff --git a/src/cmd/init.rs b/src/cmd/init.rs
index 2bea7a38..1a49f0d3 100644
--- a/src/cmd/init.rs
+++ b/src/cmd/init.rs
@@ -1,5 +1,5 @@
+use crate::get_book_dir;
use clap::{App, ArgMatches, SubCommand};
-use get_book_dir;
use mdbook::config;
use mdbook::errors::Result;
use mdbook::MDBook;
diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs
index ce194da6..3c8c53dc 100644
--- a/src/cmd/serve.rs
+++ b/src/cmd/serve.rs
@@ -1,18 +1,11 @@
-extern crate iron;
-extern crate staticfile;
-extern crate ws;
-
-use self::iron::{
- status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set,
-};
#[cfg(feature = "watch")]
use super::watch;
+use crate::{get_book_dir, open};
use clap::{App, Arg, ArgMatches, SubCommand};
+use iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set};
use mdbook::errors::*;
use mdbook::utils;
use mdbook::MDBook;
-use std;
-use {get_book_dir, open};
struct ErrorRecover;
diff --git a/src/cmd/test.rs b/src/cmd/test.rs
index cad0ae14..f6d97aa6 100644
--- a/src/cmd/test.rs
+++ b/src/cmd/test.rs
@@ -1,5 +1,5 @@
+use crate::get_book_dir;
use clap::{App, Arg, ArgMatches, SubCommand};
-use get_book_dir;
use mdbook::errors::Result;
use mdbook::MDBook;
diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs
index fc4d5c91..aa1594fa 100644
--- a/src/cmd/watch.rs
+++ b/src/cmd/watch.rs
@@ -1,15 +1,13 @@
-extern crate notify;
-
-use self::notify::Watcher;
+use crate::{get_book_dir, open};
use clap::{App, ArgMatches, SubCommand};
use mdbook::errors::Result;
use mdbook::utils;
use mdbook::MDBook;
+use notify::Watcher;
use std::path::{Path, PathBuf};
use std::sync::mpsc::channel;
use std::thread::sleep;
use std::time::Duration;
-use {get_book_dir, open};
// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
@@ -55,8 +53,8 @@ pub fn trigger_on_change<F>(book: &MDBook, closure: F)
where
F: Fn(Vec<PathBuf>, &Path),
{
- use self::notify::DebouncedEvent::*;
- use self::notify::RecursiveMode::*;
+ use notify::DebouncedEvent::*;
+ use notify::RecursiveMode::*;
// Create a channel to receive the events.
let (tx, rx) = channel();
diff --git a/src/config.rs b/src/config.rs
index 02a66421..b3707d8e 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -9,9 +9,7 @@
//! # Examples
//!
//! ```rust
-//! # extern crate mdbook;
//! # use mdbook::errors::*;
-//! # extern crate toml;
//! use std::path::PathBuf;
//! use std::str::FromStr;
//! use mdbook::Config;
@@ -52,7 +50,6 @@
#![deny(missing_docs)]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
-use serde_json;
use std::env;
use std::fs::File;
use std::io::Read;
@@ -64,7 +61,7 @@ use toml_query::delete::TomlValueDeleteExt;
use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt;
-use errors::*;
+use crate::errors::*;
/// The overall configuration object for MDBook, essentially an in-memory
/// representation of `book.toml`.
diff --git a/src/lib.rs b/src/lib.rs
index 60f63e30..0494d984 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -85,24 +85,14 @@
#[macro_use]
extern crate error_chain;
-extern crate handlebars;
-extern crate itertools;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
-extern crate memchr;
-extern crate pulldown_cmark;
-extern crate regex;
-extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
-extern crate shlex;
-extern crate tempfile;
-extern crate toml;
-extern crate toml_query;
#[cfg(test)]
#[macro_use]
@@ -121,10 +111,10 @@ pub mod utils;
/// compatibility checks.
pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION");
-pub use book::BookItem;
-pub use book::MDBook;
-pub use config::Config;
-pub use renderer::Renderer;
+pub use crate::book::BookItem;
+pub use crate::book::MDBook;
+pub use crate::config::Config;
+pub use crate::renderer::Renderer;
/// The error types used through out this crate.
pub mod errors {
diff --git a/src/main.rs b/src/main.rs
index cd711ba4..78465d7c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,7 @@
-extern crate chrono;
#[macro_use]
extern crate clap;
-extern crate env_logger;
-extern crate error_chain;
#[macro_use]
extern crate log;
-extern crate mdbook;
-extern crate open;
use chrono::Local;
use clap::{App, AppSettings, ArgMatches};
diff --git a/src/preprocess/cmd.rs b/src/preprocess/cmd.rs
index d548d90e..b16d365a 100644
--- a/src/preprocess/cmd.rs
+++ b/src/preprocess/cmd.rs
@@ -1,7 +1,6 @@
use super::{Preprocessor, PreprocessorContext};
-use book::Book;
-use errors::*;
-use serde_json;
+use crate::book::Book;
+use crate::errors::*;
use shlex::Shlex;
use std::io::{self, Read, Write};
use std::process::{Child, Command, Stdio};
@@ -168,8 +167,8 @@ impl Preprocessor for CmdPreprocessor {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::MDBook;
use std::path::Path;
- use MDBook;
fn book_example() -> MDBook {
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example");
diff --git a/src/preprocess/index.rs b/src/preprocess/index.rs
index d8e00fc1..f3256b81 100644
--- a/src/preprocess/index.rs
+++ b/src/preprocess/index.rs
@@ -1,10 +1,10 @@
use regex::Regex;
use std::path::Path;
-use errors::*;
+use crate::errors::*;
use super::{Preprocessor, PreprocessorContext};
-use book::{Book, BookItem};
+use crate::book::{Book, BookItem};
/// A preprocessor for converting file name `README.md` to `index.md` since
/// `README.md` is the de facto index file in markdown-based documentation.
diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs
index f5a86905..6ee5667a 100644
--- a/src/preprocess/links.rs
+++ b/src/preprocess/links.rs
@@ -1,12 +1,12 @@
-use errors::*;
+use crate::errors::*;
+use crate::utils::fs::file_to_string;
+use crate::utils::take_lines;
use regex::{CaptureMatches, Captures, Regex};
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
use std::path::{Path, PathBuf};
-use utils::fs::file_to_string;
-use utils::take_lines;
use super::{Preprocessor, PreprocessorContext};
-use book::{Book, BookItem};
+use crate::book::{Book, BookItem};
const ESCAPE_CHAR: char = '\\';
const MAX_LINK_NESTED_DEPTH: usize = 10;
diff --git a/src/preprocess/mod.rs b/src/preprocess/mod.rs
index 1a305408..ebc34311 100644
--- a/src/preprocess/mod.rs
+++ b/src/preprocess/mod.rs
@@ -8,9 +8,9 @@ mod cmd;
mod index;
mod links;
-use book::Book;
-use config::Config;
-use errors::*;
+use crate::book::Book;
+use crate::config::Config;
+use crate::errors::*;
use std::path::PathBuf;
@@ -37,7 +37,7 @@ impl PreprocessorContext {
root,
config,
renderer,
- mdbook_version: ::MDBOOK_VERSION.to_string(),
+ mdbook_version: crate::MDBOOK_VERSION.to_string(),
__non_exhaustive: (),
}
}
diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index 82ced929..8f3c3320 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -1,10 +1,10 @@
-use book::{Book, BookItem};
-use config::{Config, HtmlConfig, Playpen};
-use errors::*;
-use renderer::html_handlebars::helpers;
-use renderer::{RenderContext, Renderer};
-use theme::{self, playpen_editor, Theme};
-use utils;
+use crate::book::{Book, BookItem};
+use crate::config::{Config, HtmlConfig, Playpen};
+use crate::errors::*;
+use crate::renderer::html_handlebars::helpers;
+use crate::renderer::{RenderContext, Renderer};
+use crate::theme::{self, playpen_editor, Theme};
+use crate::utils;
use std::collections::BTreeMap;
use std::collections::HashMap;
@@ -13,7 +13,6 @@ use std::path::{Path, PathBuf};
use handlebars::Handlebars;
use regex::{Captures, Regex};
-use serde_json;
#[derive(Default)]
pub struct HtmlHandlebars;
@@ -113,7 +112,7 @@ impl HtmlHandlebars {
theme: &Theme,
html_config: &HtmlConfig,
) -> Result<()> {
- use utils::fs::write_file;
+ use crate::utils::fs::write_file;
write_file(
destination,
diff --git a/src/renderer/html_handlebars/helpers/navigation.rs b/src/renderer/html_handlebars/helpers/navigation.rs
index dd39400b..9264d598 100644
--- a/src/renderer/html_handlebars/helpers/navigation.rs
+++ b/src/renderer/html_handlebars/helpers/navigation.rs
@@ -2,9 +2,8 @@ use std::collections::BTreeMap;
use std::path::Path;
use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError, Renderable};
-use serde_json;
-use utils;
+use crate::utils;
type StringMap = BTreeMap<String, String>;
diff --git a/src/renderer/html_handlebars/helpers/toc.rs b/src/renderer/html_handlebars/helpers/toc.rs
index ae085e5f..27986c8f 100644
--- a/src/renderer/html_handlebars/helpers/toc.rs
+++ b/src/renderer/html_handlebars/helpers/toc.rs
@@ -1,11 +1,10 @@
use std::collections::BTreeMap;
use std::path::Path;
-use utils;
+use crate::utils;
use handlebars::{Context, Handlebars, Helper, HelperDef, Output, RenderContext, RenderError};
use pulldown_cmark::{html, Event, Parser, Tag};
-use serde_json;
// Handlebars helper to construct TOC
#[derive(Clone, Copy)]
diff --git a/src/renderer/html_handlebars/search.rs b/src/renderer/html_handlebars/search.rs
index 0531a232..c5422b39 100644
--- a/src/renderer/html_handlebars/search.rs
+++ b/src/renderer/html_handlebars/search.rs
@@ -1,19 +1,15 @@
-extern crate ammonia;
-extern crate elasticlunr;
-
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::path::Path;
-use self::elasticlunr::Index;
+use elasticlunr::Index;
use pulldown_cmark::*;
-use serde_json;
-use book::{Book, BookItem};
-use config::Search;
-use errors::*;
-use theme::searcher;
-use utils;
+use crate::book::{Book, BookItem};
+use crate::config::Search;
+use crate::errors::*;
+use crate::theme::searcher;
+use crate::utils;
/// Creates all files required for search.
pub fn create_files(search_config: &Search, destination: &Path, book: &Book) -> Result<()> {
@@ -170,7 +166,7 @@ fn render_item(
}
fn write_to_json(index: Index, search_config: &Search, doc_urls: Vec<String>) -> Result<String> {
- use self::elasticlunr::config::{SearchBool, SearchOptions, SearchOptionsField};
+ use elasticlunr::config::{SearchBool, SearchOptions, SearchOptionsField};
use std::collections::BTreeMap;
#[derive(Serialize)]
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index ae26c6ac..d4243332 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -15,16 +15,15 @@ pub use self::html_handlebars::HtmlHandlebars;
mod html_handlebars;
-use serde_json;
use shlex::Shlex;
use std::fs;
use std::io::{self, Read};
use std::path::PathBuf;
use std::process::{Command, Stdio};
-use book::Book;
-use config::Config;
-use errors::*;
+use crate::book::Book;
+use crate::config::Config;
+use crate::errors::*;
/// An arbitrary `mdbook` backend.
///
@@ -78,7 +77,7 @@ impl RenderContext {
RenderContext {
book,
config,
- version: ::MDBOOK_VERSION.to_string(),
+ version: crate::MDBOOK_VERSION.to_string(),
root: root.into(),
destination: destination.into(),
__non_exhaustive: (),
diff --git a/src/theme/mod.rs b/src/theme/mod.rs
index 37d373ef..3598322a 100644
--- a/src/theme/mod.rs
+++ b/src/theme/mod.rs
@@ -9,7 +9,7 @@ use std::fs::File;
use std::io::Read;
use std::path::Path;
-use errors::*;
+use crate::errors::*;
pub static INDEX: &'static [u8] = include_bytes!("index.hbs");
pub static HEADER: &'static [u8] = include_bytes!("header.hbs");
diff --git a/src/utils/fs.rs b/src/utils/fs.rs
index 4e0aeb7d..97d19d2f 100644
--- a/src/utils/fs.rs
+++ b/src/utils/fs.rs
@@ -1,4 +1,4 @@
-use errors::*;
+use crate::errors::*;
use std::convert::Into;
use std::fs::{self, File};
use std::io::{Read, Write};
@@ -39,8 +39,6 @@ pub fn write_file<P: AsRef<Path>>(build_dir: &Path, filename: P, content: &[u8])
/// directory from where the path starts.
///
/// ```rust
-/// # extern crate mdbook;
-/// #
/// # use std::path::Path;
/// # use mdbook::utils::fs::path_to_root;
/// #
@@ -188,8 +186,6 @@ pub fn copy_files_except_ext(
#[cfg(test)]
mod tests {
- extern crate tempfile;
-
use super::copy_files_except_ext;
use std::fs;
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 30c776fa..3f542cf8 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -2,7 +2,7 @@
pub mod fs;
mod string;
-use errors::Error;
+use crate::errors::Error;
use regex::Regex;
use pulldown_cmark::{