From 742dbbc91700dce1b7d910bca6b3e10a5ae46b86 Mon Sep 17 00:00:00 2001 From: Bas Bossink Date: Tue, 4 Dec 2018 00:11:41 +0100 Subject: [PATCH] Run rustfmt. --- examples/de-emphasize.rs | 11 +++----- examples/nop-preprocessor.rs | 12 +++------ src/cmd/init.rs | 7 ++--- src/preprocess/cmd.rs | 29 ++++++++------------- src/preprocess/mod.rs | 4 +-- src/renderer/html_handlebars/helpers/mod.rs | 2 +- tests/custom_preprocessors.rs | 9 +++++-- 7 files changed, 33 insertions(+), 41 deletions(-) diff --git a/examples/de-emphasize.rs b/examples/de-emphasize.rs index 933e5c45..fffcc44e 100644 --- a/examples/de-emphasize.rs +++ b/examples/de-emphasize.rs @@ -56,10 +56,7 @@ where Ok(()) } -fn remove_emphasis( - num_removed_items: &mut usize, - chapter: &mut Chapter, -) -> Result { +fn remove_emphasis(num_removed_items: &mut usize, chapter: &mut Chapter) -> Result { let mut buf = String::with_capacity(chapter.content.len()); let events = Parser::new(&chapter.content).filter(|e| { @@ -76,7 +73,7 @@ fn remove_emphasis( should_keep }); - cmark(events, &mut buf, None).map(|_| buf).map_err(|err| { - Error::from(format!("Markdown serialization failed: {}", err)) - }) + cmark(events, &mut buf, None) + .map(|_| buf) + .map_err(|err| Error::from(format!("Markdown serialization failed: {}", err))) } diff --git a/examples/nop-preprocessor.rs b/examples/nop-preprocessor.rs index d4615ef6..374ee60f 100644 --- a/examples/nop-preprocessor.rs +++ b/examples/nop-preprocessor.rs @@ -6,9 +6,9 @@ use clap::{App, Arg, ArgMatches, SubCommand}; use mdbook::book::Book; use mdbook::errors::Error; use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext}; +use nop_lib::Nop; use std::io; use std::process; -use nop_lib::Nop; pub fn make_app() -> App<'static, 'static> { App::new("nop-preprocessor") @@ -16,7 +16,8 @@ pub fn make_app() -> App<'static, 'static> { .subcommand( SubCommand::with_name("supports") .arg(Arg::with_name("renderer").required(true)) - .about("Check whether a renderer is supported by this preprocessor")) + .about("Check whether a renderer is supported by this preprocessor"), + ) } fn main() { @@ -87,11 +88,7 @@ mod nop_lib { "nop-preprocessor" } - fn run( - &self, - ctx: &PreprocessorContext, - book: Book, - ) -> Result { + fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result { // In testing we want to tell the preprocessor to blow up by setting a // particular config value if let Some(nop_cfg) = ctx.config.get_preprocessor(self.name()) { @@ -109,4 +106,3 @@ mod nop_lib { } } } - diff --git a/src/cmd/init.rs b/src/cmd/init.rs index 629563b2..c6bba9d5 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -12,9 +12,10 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("init") .about("Creates the boilerplate structure and files for a new book") // the {n} denotes a newline which will properly aligned in all help messages - .arg_from_usage("[dir] 'Directory to create the book in{n}\ - (Defaults to the Current Directory when omitted)'") - .arg_from_usage("--theme 'Copies the default theme into your source folder'") + .arg_from_usage( + "[dir] 'Directory to create the book in{n}\ + (Defaults to the Current Directory when omitted)'", + ).arg_from_usage("--theme 'Copies the default theme into your source folder'") .arg_from_usage("--force 'Skips confirmation prompts'") } diff --git a/src/preprocess/cmd.rs b/src/preprocess/cmd.rs index 59b0cdd3..d548d90e 100644 --- a/src/preprocess/cmd.rs +++ b/src/preprocess/cmd.rs @@ -43,19 +43,11 @@ impl CmdPreprocessor { /// A convenience function custom preprocessors can use to parse the input /// written to `stdin` by a `CmdRenderer`. - pub fn parse_input( - reader: R, - ) -> Result<(PreprocessorContext, Book)> { - serde_json::from_reader(reader) - .chain_err(|| "Unable to parse the input") + pub fn parse_input(reader: R) -> Result<(PreprocessorContext, Book)> { + serde_json::from_reader(reader).chain_err(|| "Unable to parse the input") } - fn write_input_to_child( - &self, - child: &mut Child, - book: &Book, - ctx: &PreprocessorContext, - ) { + fn write_input_to_child(&self, child: &mut Child, book: &Book, ctx: &PreprocessorContext) { let stdin = child.stdin.take().expect("Child has stdin"); if let Err(e) = self.write_input(stdin, &book, &ctx) { @@ -128,8 +120,7 @@ impl Preprocessor for CmdPreprocessor { "The preprocessor exited unsuccessfully" ); - serde_json::from_slice(&output.stdout) - .chain_err(|| "Unable to parse the preprocessed book") + serde_json::from_slice(&output.stdout).chain_err(|| "Unable to parse the preprocessed book") } fn supports_renderer(&self, renderer: &str) -> bool { @@ -142,7 +133,11 @@ impl Preprocessor for CmdPreprocessor { let mut cmd = match self.command() { Ok(c) => c, Err(e) => { - warn!("Unable to create the command for the \"{}\" preprocessor, {}", self.name(), e); + warn!( + "Unable to create the command for the \"{}\" preprocessor, {}", + self.name(), + e + ); return false; } }; @@ -177,8 +172,7 @@ mod tests { use MDBook; fn book_example() -> MDBook { - let example = - Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example"); + let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example"); MDBook::load(example).unwrap() } @@ -195,8 +189,7 @@ mod tests { let mut buffer = Vec::new(); cmd.write_input(&mut buffer, &md.book, &ctx).unwrap(); - let (got_ctx, got_book) = - CmdPreprocessor::parse_input(buffer.as_slice()).unwrap(); + let (got_ctx, got_book) = CmdPreprocessor::parse_input(buffer.as_slice()).unwrap(); assert_eq!(got_book, md.book); assert_eq!(got_ctx, ctx); diff --git a/src/preprocess/mod.rs b/src/preprocess/mod.rs index 917ab5ca..1a305408 100644 --- a/src/preprocess/mod.rs +++ b/src/preprocess/mod.rs @@ -1,12 +1,12 @@ //! Book preprocessing. +pub use self::cmd::CmdPreprocessor; pub use self::index::IndexPreprocessor; pub use self::links::LinkPreprocessor; -pub use self::cmd::CmdPreprocessor; +mod cmd; mod index; mod links; -mod cmd; use book::Book; use config::Config; diff --git a/src/renderer/html_handlebars/helpers/mod.rs b/src/renderer/html_handlebars/helpers/mod.rs index e9a8f932..52be6d20 100644 --- a/src/renderer/html_handlebars/helpers/mod.rs +++ b/src/renderer/html_handlebars/helpers/mod.rs @@ -1,3 +1,3 @@ pub mod navigation; +pub mod theme; pub mod toc; -pub mod theme; \ No newline at end of file diff --git a/tests/custom_preprocessors.rs b/tests/custom_preprocessors.rs index 54bfd51d..dd120eab 100644 --- a/tests/custom_preprocessors.rs +++ b/tests/custom_preprocessors.rs @@ -7,7 +7,10 @@ use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; use mdbook::MDBook; fn example() -> CmdPreprocessor { - CmdPreprocessor::new("nop-preprocessor".to_string(), "cargo run --example nop-preprocessor --".to_string()) + CmdPreprocessor::new( + "nop-preprocessor".to_string(), + "cargo run --example nop-preprocessor --".to_string(), + ) } #[test] @@ -35,7 +38,9 @@ fn ask_the_preprocessor_to_blow_up() { let mut md = MDBook::load(temp.path()).unwrap(); md.with_preprecessor(example()); - md.config.set("preprocessor.nop-preprocessor.blow-up", true).unwrap(); + md.config + .set("preprocessor.nop-preprocessor.blow-up", true) + .unwrap(); let got = md.build();