Skip to content

Commit 70f86c1

Browse files
committed
format using rustfmt rust-lang#398
1 parent 92c505a commit 70f86c1

File tree

16 files changed

+397
-423
lines changed

16 files changed

+397
-423
lines changed

src/book/bookitem.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub struct BookItems<'a> {
2727

2828
impl Chapter {
2929
pub fn new(name: String, path: PathBuf) -> Self {
30-
3130
Chapter {
3231
name: name,
3332
path: path,
@@ -39,7 +38,8 @@ impl Chapter {
3938

4039
impl Serialize for Chapter {
4140
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
42-
where S: Serializer
41+
where
42+
S: Serializer,
4343
{
4444
let mut struct_ = serializer.serialize_struct("Chapter", 2)?;
4545
struct_.serialize_field("name", &self.name)?;
@@ -69,8 +69,7 @@ impl<'a> Iterator for BookItems<'a> {
6969
let cur = &self.items[self.current_index];
7070

7171
match *cur {
72-
BookItem::Chapter(_, ref ch) |
73-
BookItem::Affix(ref ch) => {
72+
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => {
7473
self.stack.push((self.items, self.current_index));
7574
self.items = &ch.sub_items[..];
7675
self.current_index = 0;

src/book/mod.rs

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::io::{Read, Write};
88
use std::process::Command;
99
use tempdir::TempDir;
1010

11-
use {theme, parse, utils};
12-
use renderer::{Renderer, HtmlHandlebars};
11+
use {parse, theme, utils};
12+
use renderer::{HtmlHandlebars, Renderer};
1313
use preprocess;
1414
use errors::*;
1515

@@ -60,7 +60,6 @@ impl MDBook {
6060
/// [`set_dest()`](#method.set_dest)
6161
6262
pub fn new<P: Into<PathBuf>>(root: P) -> MDBook {
63-
6463
let root = root.into();
6564
if !root.exists() || !root.is_dir() {
6665
warn!("{:?} No directory with that name", root);
@@ -130,7 +129,6 @@ impl MDBook {
130129
/// `chapter_1.md` to the source directory.
131130
132131
pub fn init(&mut self) -> Result<()> {
133-
134132
debug!("[fn]: init");
135133

136134
if !self.config.get_root().exists() {
@@ -139,7 +137,6 @@ impl MDBook {
139137
}
140138

141139
{
142-
143140
if !self.get_destination().exists() {
144141
debug!("[*]: {:?} does not exist, trying to create directory", self.get_destination());
145142
fs::create_dir_all(self.get_destination())?;
@@ -154,7 +151,6 @@ impl MDBook {
154151
let summary = self.config.get_source().join("SUMMARY.md");
155152

156153
if !summary.exists() {
157-
158154
// Summary does not exist, create it
159155
debug!("[*]: {:?} does not exist, trying to create SUMMARY.md", &summary);
160156
let mut f = File::create(&summary)?;
@@ -175,16 +171,14 @@ impl MDBook {
175171
debug!("[*]: item: {:?}", item);
176172
let ch = match *item {
177173
BookItem::Spacer => continue,
178-
BookItem::Chapter(_, ref ch) |
179-
BookItem::Affix(ref ch) => ch,
174+
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => ch,
180175
};
181176
if !ch.path.as_os_str().is_empty() {
182177
let path = self.config.get_source().join(&ch.path);
183178

184179
if !path.exists() {
185180
if !self.create_missing {
186-
return Err(format!("'{}' referenced from SUMMARY.md does not exist.", path.to_string_lossy())
187-
.into());
181+
return Err(format!("'{}' referenced from SUMMARY.md does not exist.", path.to_string_lossy()).into());
188182
}
189183
debug!("[*]: {:?} does not exist, trying to create file", path);
190184
::std::fs::create_dir_all(path.parent().unwrap())?;
@@ -203,14 +197,15 @@ impl MDBook {
203197
pub fn create_gitignore(&self) {
204198
let gitignore = self.get_gitignore();
205199

206-
let destination = self.config.get_html_config()
207-
.get_destination();
200+
let destination = self.config.get_html_config().get_destination();
208201

209-
// Check that the gitignore does not extist and that the destination path begins with the root path
210-
// We assume tha if it does begin with the root path it is contained within. This assumption
211-
// will not hold true for paths containing double dots to go back up e.g. `root/../destination`
202+
// Check that the gitignore does not extist and that the destination path
203+
// begins with the root path
204+
// We assume tha if it does begin with the root path it is contained within.
205+
// This assumption
206+
// will not hold true for paths containing double dots to go back up e.g.
207+
// `root/../destination`
212208
if !gitignore.exists() && destination.starts_with(self.config.get_root()) {
213-
214209
let relative = destination
215210
.strip_prefix(self.config.get_root())
216211
.expect("Could not strip the root prefix, path is not relative to root")
@@ -286,8 +281,7 @@ impl MDBook {
286281
}
287282

288283
pub fn write_file<P: AsRef<Path>>(&self, filename: P, content: &[u8]) -> Result<()> {
289-
let path = self.get_destination()
290-
.join(filename);
284+
let path = self.get_destination().join(filename);
291285

292286
utils::fs::create_file(&path)?
293287
.write_all(content)
@@ -300,7 +294,6 @@ impl MDBook {
300294
/// The root directory is the one specified when creating a new `MDBook`
301295
302296
pub fn read_config(mut self) -> Result<Self> {
303-
304297
let toml = self.get_root().join("book.toml");
305298
let json = self.get_root().join("book.json");
306299

@@ -356,31 +349,33 @@ impl MDBook {
356349
pub fn test(&mut self, library_paths: Vec<&str>) -> Result<()> {
357350
// read in the chapters
358351
self.parse_summary().chain_err(|| "Couldn't parse summary")?;
359-
let library_args: Vec<&str> = (0..library_paths.len()).map(|_| "-L")
360-
.zip(library_paths.into_iter())
361-
.flat_map(|x| vec![x.0, x.1])
362-
.collect();
352+
let library_args: Vec<&str> = (0..library_paths.len())
353+
.map(|_| "-L")
354+
.zip(library_paths.into_iter())
355+
.flat_map(|x| vec![x.0, x.1])
356+
.collect();
363357
let temp_dir = TempDir::new("mdbook")?;
364358
for item in self.iter() {
365-
366359
if let BookItem::Chapter(_, ref ch) = *item {
367360
if !ch.path.as_os_str().is_empty() {
368-
369361
let path = self.get_source().join(&ch.path);
370-
let base = path.parent().ok_or_else(
371-
|| String::from("Invalid bookitem path!"),
372-
)?;
362+
let base = path.parent()
363+
.ok_or_else(|| String::from("Invalid bookitem path!"))?;
373364
let content = utils::fs::file_to_string(&path)?;
374365
// Parse and expand links
375366
let content = preprocess::links::replace_all(&content, base)?;
376367
println!("[*]: Testing file: {:?}", path);
377368

378-
//write preprocessed file to tempdir
369+
// write preprocessed file to tempdir
379370
let path = temp_dir.path().join(&ch.path);
380371
let mut tmpf = utils::fs::create_file(&path)?;
381372
tmpf.write_all(content.as_bytes())?;
382373

383-
let output = Command::new("rustdoc").arg(&path).arg("--test").args(&library_args).output()?;
374+
let output = Command::new("rustdoc")
375+
.arg(&path)
376+
.arg("--test")
377+
.args(&library_args)
378+
.output()?;
384379

385380
if !output.status.success() {
386381
bail!(ErrorKind::Subprocess("Rustdoc returned an error".to_string(), output));
@@ -398,15 +393,15 @@ impl MDBook {
398393

399394
pub fn with_destination<T: Into<PathBuf>>(mut self, destination: T) -> Self {
400395
let root = self.config.get_root().to_owned();
401-
self.config.get_mut_html_config()
396+
self.config
397+
.get_mut_html_config()
402398
.set_destination(&root, &destination.into());
403399
self
404400
}
405401

406402

407403
pub fn get_destination(&self) -> &Path {
408-
self.config.get_html_config()
409-
.get_destination()
404+
self.config.get_html_config().get_destination()
410405
}
411406

412407
pub fn with_source<T: Into<PathBuf>>(mut self, source: T) -> Self {
@@ -452,61 +447,56 @@ impl MDBook {
452447

453448
pub fn with_theme_path<T: Into<PathBuf>>(mut self, theme_path: T) -> Self {
454449
let root = self.config.get_root().to_owned();
455-
self.config.get_mut_html_config()
450+
self.config
451+
.get_mut_html_config()
456452
.set_theme(&root, &theme_path.into());
457453
self
458454
}
459455

460456
pub fn get_theme_path(&self) -> &Path {
461-
self.config.get_html_config()
462-
.get_theme()
457+
self.config.get_html_config().get_theme()
463458
}
464459

465460
pub fn with_curly_quotes(mut self, curly_quotes: bool) -> Self {
466-
self.config.get_mut_html_config()
461+
self.config
462+
.get_mut_html_config()
467463
.set_curly_quotes(curly_quotes);
468464
self
469465
}
470466

471467
pub fn get_curly_quotes(&self) -> bool {
472-
self.config.get_html_config()
473-
.get_curly_quotes()
468+
self.config.get_html_config().get_curly_quotes()
474469
}
475470

476471
pub fn with_mathjax_support(mut self, mathjax_support: bool) -> Self {
477-
self.config.get_mut_html_config()
472+
self.config
473+
.get_mut_html_config()
478474
.set_mathjax_support(mathjax_support);
479475
self
480476
}
481477

482478
pub fn get_mathjax_support(&self) -> bool {
483-
self.config.get_html_config()
484-
.get_mathjax_support()
479+
self.config.get_html_config().get_mathjax_support()
485480
}
486481

487482
pub fn get_google_analytics_id(&self) -> Option<String> {
488-
self.config.get_html_config()
489-
.get_google_analytics_id()
483+
self.config.get_html_config().get_google_analytics_id()
490484
}
491485

492486
pub fn has_additional_js(&self) -> bool {
493-
self.config.get_html_config()
494-
.has_additional_js()
487+
self.config.get_html_config().has_additional_js()
495488
}
496489

497490
pub fn get_additional_js(&self) -> &[PathBuf] {
498-
self.config.get_html_config()
499-
.get_additional_js()
491+
self.config.get_html_config().get_additional_js()
500492
}
501493

502494
pub fn has_additional_css(&self) -> bool {
503-
self.config.get_html_config()
504-
.has_additional_css()
495+
self.config.get_html_config().has_additional_css()
505496
}
506497

507498
pub fn get_additional_css(&self) -> &[PathBuf] {
508-
self.config.get_html_config()
509-
.get_additional_css()
499+
self.config.get_html_config().get_additional_css()
510500
}
511501

512502
pub fn get_html_config(&self) -> &HtmlConfig {

src/config/bookconfig.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use std::path::{PathBuf, Path};
1+
use std::path::{Path, PathBuf};
22

33
use super::HtmlConfig;
44
use super::tomlconfig::TomlConfig;
55
use super::jsonconfig::JsonConfig;
66

7-
/// Configuration struct containing all the configuration options available in mdBook.
7+
/// Configuration struct containing all the configuration options available in
8+
/// mdBook.
89
#[derive(Debug, Clone, PartialEq, Eq)]
910
pub struct BookConfig {
1011
root: PathBuf,
@@ -21,8 +22,10 @@ pub struct BookConfig {
2122
}
2223

2324
impl BookConfig {
24-
/// Creates a new `BookConfig` struct with as root path the path given as parameter.
25-
/// The source directory is `root/src` and the destination for the rendered book is `root/book`.
25+
/// Creates a new `BookConfig` struct with as root path the path given as
26+
/// parameter.
27+
/// The source directory is `root/src` and the destination for the rendered
28+
/// book is `root/book`.
2629
///
2730
/// ```
2831
/// # use std::path::PathBuf;
@@ -32,8 +35,10 @@ impl BookConfig {
3235
/// let config = BookConfig::new(&root);
3336
///
3437
/// assert_eq!(config.get_root(), &root);
35-
/// assert_eq!(config.get_source(), PathBuf::from("directory/to/my/book/src"));
36-
/// assert_eq!(config.get_html_config(), &HtmlConfig::new(PathBuf::from("directory/to/my/book")));
38+
/// assert_eq!(config.get_source(),
39+
/// PathBuf::from("directory/to/my/book/src"));
40+
/// assert_eq!(config.get_html_config(),
41+
/// &HtmlConfig::new(PathBuf::from("directory/to/my/book")));
3742
/// ```
3843
pub fn new<T: Into<PathBuf>>(root: T) -> Self {
3944
let root: PathBuf = root.into();
@@ -86,7 +91,6 @@ impl BookConfig {
8691
}
8792

8893
pub fn fill_from_tomlconfig(&mut self, tomlconfig: TomlConfig) -> &mut Self {
89-
9094
if let Some(s) = tomlconfig.source {
9195
self.set_source(s);
9296
}
@@ -112,11 +116,12 @@ impl BookConfig {
112116
self.get_mut_html_config()
113117
.fill_from_tomlconfig(root, tomlhtmlconfig);
114118
}
115-
119+
116120
self
117121
}
118122

119-
/// The JSON configuration file is **deprecated** and should not be used anymore.
123+
/// The JSON configuration file is **deprecated** and should not be used
124+
/// anymore.
120125
/// Please, migrate to the TOML configuration file.
121126
pub fn from_jsonconfig<T: Into<PathBuf>>(root: T, jsonconfig: JsonConfig) -> Self {
122127
let root = root.into();
@@ -125,10 +130,10 @@ impl BookConfig {
125130
config
126131
}
127132

128-
/// The JSON configuration file is **deprecated** and should not be used anymore.
133+
/// The JSON configuration file is **deprecated** and should not be used
134+
/// anymore.
129135
/// Please, migrate to the TOML configuration file.
130136
pub fn fill_from_jsonconfig(&mut self, jsonconfig: JsonConfig) -> &mut Self {
131-
132137
if let Some(s) = jsonconfig.src {
133138
self.set_source(s);
134139
}
@@ -147,14 +152,12 @@ impl BookConfig {
147152

148153
if let Some(d) = jsonconfig.dest {
149154
let root = self.get_root().to_owned();
150-
self.get_mut_html_config()
151-
.set_destination(&root, &d);
155+
self.get_mut_html_config().set_destination(&root, &d);
152156
}
153157

154158
if let Some(d) = jsonconfig.theme_path {
155159
let root = self.get_root().to_owned();
156-
self.get_mut_html_config()
157-
.set_theme(&root, &d);
160+
self.get_mut_html_config().set_theme(&root, &d);
158161
}
159162

160163
self
@@ -218,7 +221,8 @@ impl BookConfig {
218221
self
219222
}
220223

221-
/// Returns the configuration for the HTML renderer or None of there isn't any
224+
/// Returns the configuration for the HTML renderer or None of there isn't
225+
/// any
222226
pub fn get_html_config(&self) -> &HtmlConfig {
223227
&self.html_config
224228
}

src/config/htmlconfig.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{PathBuf, Path};
1+
use std::path::{Path, PathBuf};
22

33
use super::tomlconfig::TomlHtmlConfig;
44
use super::playpenconfig::PlaypenConfig;
@@ -16,7 +16,8 @@ pub struct HtmlConfig {
1616
}
1717

1818
impl HtmlConfig {
19-
/// Creates a new `HtmlConfig` struct containing the configuration parameters for the HTML renderer.
19+
/// Creates a new `HtmlConfig` struct containing the configuration
20+
/// parameters for the HTML renderer.
2021
///
2122
/// ```
2223
/// # use std::path::PathBuf;

0 commit comments

Comments
 (0)