From 56051beaea102578916baad99b71afb0b3465c22 Mon Sep 17 00:00:00 2001 From: Yuriy Larin Date: Wed, 21 Jun 2023 10:45:30 +0300 Subject: [PATCH] rust fmt fixes --- src/book/mod.rs | 2 +- src/preprocess/links.rs | 31 ++++++++++++++++++++++++++----- src/preprocess/mod.rs | 5 ++++- src/utils/string.rs | 18 ++++++++++++++---- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 633f74e67e..391c1efc34 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -435,7 +435,7 @@ impl MDBook { pub fn clone_preprocessors(&self) -> Vec> { self.preprocessors.clone() } - } +} /// Look at the `Config` and try to figure out what renderers to use. fn determine_renderers(config: &Config) -> Vec> { diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index cdf2d6b22a..aa88eafac9 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -62,7 +62,13 @@ impl Preprocessor for LinkPreprocessor { let mut chapter_title = ch.name.clone(); // run normal link replacement by all content with 'dashed' lines inside present let content = replace_all( - &ch.content, base, chapter_path, 0, &mut chapter_title, false); + &ch.content, + base, + chapter_path, + 0, + &mut chapter_title, + false, + ); ch.content = content; if chapter_title != ch.name { ctx.chapter_titles @@ -91,7 +97,13 @@ impl Preprocessor for LinkPreprocessor { // by lined content with removing # dashed lines let mut chapter_title:String = chapter.name.clone(); let updated_content = replace_all( - &chapter.content.clone(), base, chapter_path, 0, chapter_title.as_mut_string(), true); + &chapter.content.clone(), + base, + chapter_path, + 0, + chapter_title.as_mut_string(), + true, + ); trace!("updated_content = {:?}", updated_content.len()); chapter.content = updated_content; } @@ -479,7 +491,10 @@ mod tests { {{#include file.rs}} << an escaped link! ```"; let mut chapter_title = "test_replace_all_escaped".to_owned(); - assert_eq!(replace_all(start, "", "", 0, &mut chapter_title, false), end); + assert_eq!( + replace_all(start, "", "", 0, &mut chapter_title, false), + end + ); } @@ -510,7 +525,10 @@ mod tests { {{#include file.rs}} << an escaped link! ```"; let mut chapter_title = "test_replace_all_escaped_with_cutoff".to_owned(); - assert_eq!(replace_all(start, "", "", 0, &mut chapter_title, false), end); + assert_eq!( + replace_all(start, "", "", 0, &mut chapter_title, false), + end + ); } #[test] @@ -522,7 +540,10 @@ mod tests { # My Chapter "; let mut chapter_title = "test_set_chapter_title".to_owned(); - assert_eq!(replace_all(start, "", "", 0, &mut chapter_title, false), end); + assert_eq!( + replace_all(start, "", "", 0, &mut chapter_title, false), + end + ); assert_eq!(chapter_title, "My Title"); } diff --git a/src/preprocess/mod.rs b/src/preprocess/mod.rs index 156c517f94..7173b5583e 100644 --- a/src/preprocess/mod.rs +++ b/src/preprocess/mod.rs @@ -64,7 +64,10 @@ pub trait Preprocessor: PreprocessorClone { /// Pre-Process only one mutable chapter using context and supplied pre-processor fn preprocess_chapter(&self, ctx: &PreprocessorContext, chapter: &mut Chapter) -> Result<()> { - println!("preprocess chapter: '{}' by ctx = {}", chapter.name, ctx.renderer); + println!( + "preprocess chapter: '{}' by ctx = {}", + chapter.name, ctx.renderer + ); Ok(()) } diff --git a/src/utils/string.rs b/src/utils/string.rs index d6cfe96683..eb5ead29a8 100644 --- a/src/utils/string.rs +++ b/src/utils/string.rs @@ -63,12 +63,17 @@ pub fn take_anchored_lines(s: &str, anchor: &str) -> String { /// For any lines not in the range, include them but use `#` at the beginning. This will hide the /// lines from initial display but include them when expanding the code snippet or testing with /// rustdoc. -pub fn take_rustdoc_include_lines>(s: &str, range: R, cutoff_commented_lines: bool) -> String { +pub fn take_rustdoc_include_lines>( + s: &str, + range: R, + cutoff_commented_lines: bool, +) -> String { let mut output = String::with_capacity(s.len()); for (index, line) in s.lines().enumerate() { if !range.contains(&index) { - if !cutoff_commented_lines { // do not include 'dashed' lines (for epub format) + if !cutoff_commented_lines { + // do not include 'dashed' lines (for epub format) output.push_str("# "); } } @@ -84,7 +89,11 @@ pub fn take_rustdoc_include_lines>(s: &str, range: R, cuto /// For any lines not between the anchors, include them but use `#` at the beginning. This will /// hide the lines from initial display but include them when expanding the code snippet or testing /// with rustdoc. The cutoff_commented_lines = true, means do not include code lines started with #... -pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str, cutoff_commented_lines: bool) -> String { +pub fn take_rustdoc_include_anchored_lines( + s: &str, + anchor: &str, + cutoff_commented_lines: bool, +) -> String { let mut output = String::with_capacity(s.len()); let mut within_anchored_section = false; @@ -108,7 +117,8 @@ pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str, cutoff_comment within_anchored_section = true; } } else if !ANCHOR_END.is_match(l) { - if !cutoff_commented_lines { // do not include 'dashed' lines (for epub format) + if !cutoff_commented_lines { + // do not include 'dashed' lines (for epub format) output.push_str("# "); output.push_str(l); output.push('\n');