Fix many minor warnings found by clippy
This commit is contained in:
parent
5960050676
commit
b164e0709b
|
@ -47,10 +47,7 @@ impl BookConfig {
|
||||||
|
|
||||||
// Just return if an error occured.
|
// Just return if an error occured.
|
||||||
// I would like to propagate the error, but I have to return `&self`
|
// I would like to propagate the error, but I have to return `&self`
|
||||||
match config_file.read_to_string(&mut data) {
|
if let Err(_) = config_file.read_to_string(&mut data) { return self }
|
||||||
Err(_) => return self,
|
|
||||||
_ => {},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to JSON
|
// Convert to JSON
|
||||||
if let Ok(config) = Json::from_str(&data) {
|
if let Ok(config) = Json::from_str(&data) {
|
||||||
|
|
|
@ -43,8 +43,8 @@ impl ToJson for Chapter {
|
||||||
|
|
||||||
fn to_json(&self) -> Json {
|
fn to_json(&self) -> Json {
|
||||||
let mut m: BTreeMap<String, Json> = BTreeMap::new();
|
let mut m: BTreeMap<String, Json> = BTreeMap::new();
|
||||||
m.insert("name".to_string(), self.name.to_json());
|
m.insert("name".to_owned(), self.name.to_json());
|
||||||
m.insert("path".to_string(),self.path.to_str()
|
m.insert("path".to_owned(),self.path.to_str()
|
||||||
.expect("Json conversion failed for path").to_json()
|
.expect("Json conversion failed for path").to_json()
|
||||||
);
|
);
|
||||||
m.to_json()
|
m.to_json()
|
||||||
|
@ -71,13 +71,13 @@ impl<'a> Iterator for BookItems<'a> {
|
||||||
} else {
|
} else {
|
||||||
let cur = self.items.get(self.current_index).unwrap();
|
let cur = self.items.get(self.current_index).unwrap();
|
||||||
|
|
||||||
match cur {
|
match *cur {
|
||||||
&BookItem::Chapter(_, ref ch) | &BookItem::Affix(ref ch) => {
|
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => {
|
||||||
self.stack.push((self.items, self.current_index));
|
self.stack.push((self.items, self.current_index));
|
||||||
self.items = &ch.sub_items[..];
|
self.items = &ch.sub_items[..];
|
||||||
self.current_index = 0;
|
self.current_index = 0;
|
||||||
},
|
},
|
||||||
&BookItem::Spacer => {
|
BookItem::Spacer => {
|
||||||
self.current_index += 1;
|
self.current_index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,9 +134,9 @@ impl MDBook {
|
||||||
debug!("[*]: constructing paths for missing files");
|
debug!("[*]: constructing paths for missing files");
|
||||||
for item in self.iter() {
|
for item in self.iter() {
|
||||||
debug!("[*]: item: {:?}", item);
|
debug!("[*]: item: {:?}", item);
|
||||||
match item {
|
match *item {
|
||||||
&BookItem::Spacer => continue,
|
BookItem::Spacer => continue,
|
||||||
&BookItem::Chapter(_, ref ch) | &BookItem::Affix(ref ch) => {
|
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => {
|
||||||
if ch.path != PathBuf::new() {
|
if ch.path != PathBuf::new() {
|
||||||
let path = self.config.get_src().join(&ch.path);
|
let path = self.config.get_src().join(&ch.path);
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ impl MDBook {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("[*]: init done");
|
debug!("[*]: init done");
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The `build()` method is the one where everything happens. First it parses `SUMMARY.md` to
|
/// The `build()` method is the one where everything happens. First it parses `SUMMARY.md` to
|
||||||
|
|
|
@ -19,7 +19,7 @@ fn parse_level(summary: &mut Vec<&str>, current_level: i32, mut section: Vec<i32
|
||||||
let mut items: Vec<BookItem> = vec![];
|
let mut items: Vec<BookItem> = vec![];
|
||||||
|
|
||||||
// Construct the book recursively
|
// Construct the book recursively
|
||||||
while summary.len() > 0 {
|
while !summary.is_empty() {
|
||||||
let item: BookItem;
|
let item: BookItem;
|
||||||
// Indentation level of the line to parse
|
// Indentation level of the line to parse
|
||||||
let level = try!(level(summary[0], 4));
|
let level = try!(level(summary[0], 4));
|
||||||
|
@ -199,7 +199,7 @@ fn read_link(line: &str) -> Option<(String, PathBuf)> {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = line[start_delimitor + 1 .. end_delimitor].to_string();
|
let name = line[start_delimitor + 1 .. end_delimitor].to_owned();
|
||||||
|
|
||||||
start_delimitor = end_delimitor + 1;
|
start_delimitor = end_delimitor + 1;
|
||||||
if let Some(i) = line[start_delimitor..].find(')') {
|
if let Some(i) = line[start_delimitor..].find(')') {
|
||||||
|
@ -210,7 +210,7 @@ fn read_link(line: &str) -> Option<(String, PathBuf)> {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = PathBuf::from(line[start_delimitor + 1 .. end_delimitor].to_string());
|
let path = PathBuf::from(line[start_delimitor + 1 .. end_delimitor].to_owned());
|
||||||
|
|
||||||
Some((name, path))
|
Some((name, path))
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,17 +51,16 @@ impl Renderer for HtmlHandlebars {
|
||||||
|
|
||||||
// Check if dest directory exists
|
// Check if dest directory exists
|
||||||
debug!("[*]: Check if destination directory exists");
|
debug!("[*]: Check if destination directory exists");
|
||||||
match utils::create_path(book.get_dest()) {
|
if let Err(_) = utils::create_path(book.get_dest()) {
|
||||||
Err(_) => return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Unexcpected error when constructing destination path"))),
|
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Unexpected error when constructing destination path")))
|
||||||
_ => {},
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// Render a file for every entry in the book
|
// Render a file for every entry in the book
|
||||||
let mut index = true;
|
let mut index = true;
|
||||||
for item in book.iter() {
|
for item in book.iter() {
|
||||||
|
|
||||||
match item {
|
match *item {
|
||||||
&BookItem::Chapter(_, ref ch) | &BookItem::Affix(ref ch) => {
|
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => {
|
||||||
if ch.path != PathBuf::new() {
|
if ch.path != PathBuf::new() {
|
||||||
|
|
||||||
let path = book.get_src().join(&ch.path);
|
let path = book.get_src().join(&ch.path);
|
||||||
|
@ -80,18 +79,18 @@ impl Renderer for HtmlHandlebars {
|
||||||
// Remove content from previous file and render content for this one
|
// Remove content from previous file and render content for this one
|
||||||
data.remove("path");
|
data.remove("path");
|
||||||
match ch.path.to_str() {
|
match ch.path.to_str() {
|
||||||
Some(p) => { data.insert("path".to_string(), p.to_json()); },
|
Some(p) => { data.insert("path".to_owned(), p.to_json()); },
|
||||||
None => return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not convert path to str"))),
|
None => return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not convert path to str"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Remove content from previous file and render content for this one
|
// Remove content from previous file and render content for this one
|
||||||
data.remove("content");
|
data.remove("content");
|
||||||
data.insert("content".to_string(), content.to_json());
|
data.insert("content".to_owned(), content.to_json());
|
||||||
|
|
||||||
// Remove path to root from previous file and render content for this one
|
// Remove path to root from previous file and render content for this one
|
||||||
data.remove("path_to_root");
|
data.remove("path_to_root");
|
||||||
data.insert("path_to_root".to_string(), utils::path_to_root(&ch.path).to_json());
|
data.insert("path_to_root".to_owned(), utils::path_to_root(&ch.path).to_json());
|
||||||
|
|
||||||
// Rendere the handlebars template with the data
|
// Rendere the handlebars template with the data
|
||||||
debug!("[*]: Render template");
|
debug!("[*]: Render template");
|
||||||
|
@ -135,15 +134,15 @@ impl Renderer for HtmlHandlebars {
|
||||||
|
|
||||||
// Remove content from previous file and render content for this one
|
// Remove content from previous file and render content for this one
|
||||||
data.remove("path");
|
data.remove("path");
|
||||||
data.insert("path".to_string(), "print.md".to_json());
|
data.insert("path".to_owned(), "print.md".to_json());
|
||||||
|
|
||||||
// Remove content from previous file and render content for this one
|
// Remove content from previous file and render content for this one
|
||||||
data.remove("content");
|
data.remove("content");
|
||||||
data.insert("content".to_string(), print_content.to_json());
|
data.insert("content".to_owned(), print_content.to_json());
|
||||||
|
|
||||||
// Remove path to root from previous file and render content for this one
|
// Remove path to root from previous file and render content for this one
|
||||||
data.remove("path_to_root");
|
data.remove("path_to_root");
|
||||||
data.insert("path_to_root".to_string(), utils::path_to_root(Path::new("print.md")).to_json());
|
data.insert("path_to_root".to_owned(), utils::path_to_root(Path::new("print.md")).to_json());
|
||||||
|
|
||||||
// Rendere the handlebars template with the data
|
// Rendere the handlebars template with the data
|
||||||
debug!("[*]: Render template");
|
debug!("[*]: Render template");
|
||||||
|
@ -199,8 +198,8 @@ fn make_data(book: &MDBook) -> Result<BTreeMap<String,Json>, Box<Error>> {
|
||||||
debug!("[fn]: make_data");
|
debug!("[fn]: make_data");
|
||||||
|
|
||||||
let mut data = BTreeMap::new();
|
let mut data = BTreeMap::new();
|
||||||
data.insert("language".to_string(), "en".to_json());
|
data.insert("language".to_owned(), "en".to_json());
|
||||||
data.insert("title".to_string(), book.get_title().to_json());
|
data.insert("title".to_owned(), book.get_title().to_json());
|
||||||
|
|
||||||
let mut chapters = vec![];
|
let mut chapters = vec![];
|
||||||
|
|
||||||
|
@ -208,24 +207,24 @@ fn make_data(book: &MDBook) -> Result<BTreeMap<String,Json>, Box<Error>> {
|
||||||
// Create the data to inject in the template
|
// Create the data to inject in the template
|
||||||
let mut chapter = BTreeMap::new();
|
let mut chapter = BTreeMap::new();
|
||||||
|
|
||||||
match item {
|
match *item {
|
||||||
&BookItem::Affix(ref ch) => {
|
BookItem::Affix(ref ch) => {
|
||||||
chapter.insert("name".to_string(), ch.name.to_json());
|
chapter.insert("name".to_owned(), ch.name.to_json());
|
||||||
match ch.path.to_str() {
|
match ch.path.to_str() {
|
||||||
Some(p) => { chapter.insert("path".to_string(), p.to_json()); },
|
Some(p) => { chapter.insert("path".to_owned(), p.to_json()); },
|
||||||
None => return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not convert path to str"))),
|
None => return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not convert path to str"))),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&BookItem::Chapter(ref s, ref ch) => {
|
BookItem::Chapter(ref s, ref ch) => {
|
||||||
chapter.insert("section".to_string(), s.to_json());
|
chapter.insert("section".to_owned(), s.to_json());
|
||||||
chapter.insert("name".to_string(), ch.name.to_json());
|
chapter.insert("name".to_owned(), ch.name.to_json());
|
||||||
match ch.path.to_str() {
|
match ch.path.to_str() {
|
||||||
Some(p) => { chapter.insert("path".to_string(), p.to_json()); },
|
Some(p) => { chapter.insert("path".to_owned(), p.to_json()); },
|
||||||
None => return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not convert path to str"))),
|
None => return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not convert path to str"))),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&BookItem::Spacer => {
|
BookItem::Spacer => {
|
||||||
chapter.insert("spacer".to_string(), "_spacer_".to_json());
|
chapter.insert("spacer".to_owned(), "_spacer_".to_json());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -233,7 +232,7 @@ fn make_data(book: &MDBook) -> Result<BTreeMap<String,Json>, Box<Error>> {
|
||||||
chapters.push(chapter);
|
chapters.push(chapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.insert("chapters".to_string(), chapters.to_json());
|
data.insert("chapters".to_owned(), chapters.to_json());
|
||||||
|
|
||||||
debug!("[*]: JSON constructed");
|
debug!("[*]: JSON constructed");
|
||||||
Ok(data)
|
Ok(data)
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
|
||||||
for item in decoded {
|
for item in decoded {
|
||||||
|
|
||||||
match item.get("path") {
|
match item.get("path") {
|
||||||
Some(path) if path.len() > 0 => {
|
Some(path) if !path.is_empty() => {
|
||||||
if path == ¤t {
|
if path == ¤t {
|
||||||
|
|
||||||
debug!("[*]: Found current chapter");
|
debug!("[*]: Found current chapter");
|
||||||
|
@ -51,7 +51,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
|
||||||
match previous.get("name") {
|
match previous.get("name") {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
debug!("[*]: Inserting title: {}", n);
|
debug!("[*]: Inserting title: {}", n);
|
||||||
previous_chapter.insert("title".to_string(), n.to_json())
|
previous_chapter.insert("title".to_owned(), n.to_json())
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
debug!("[*]: No title found for chapter");
|
debug!("[*]: No title found for chapter");
|
||||||
|
@ -67,7 +67,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
|
||||||
debug!("[*]: Inserting link: {:?}", path);
|
debug!("[*]: Inserting link: {:?}", path);
|
||||||
|
|
||||||
match path.to_str() {
|
match path.to_str() {
|
||||||
Some(p) => { previous_chapter.insert("link".to_string(), p.to_json()); },
|
Some(p) => { previous_chapter.insert("link".to_owned(), p.to_json()); },
|
||||||
None => return Err(RenderError{ desc: "Link could not be converted to str" })
|
None => return Err(RenderError{ desc: "Link could not be converted to str" })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -134,7 +134,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
|
||||||
|
|
||||||
match item.get("path") {
|
match item.get("path") {
|
||||||
|
|
||||||
Some(path) if path.len() > 0 => {
|
Some(path) if !path.is_empty() => {
|
||||||
|
|
||||||
if let Some(previous) = previous {
|
if let Some(previous) = previous {
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
|
||||||
match item.get("name") {
|
match item.get("name") {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
debug!("[*]: Inserting title: {}", n);
|
debug!("[*]: Inserting title: {}", n);
|
||||||
next_chapter.insert("title".to_string(), n.to_json());
|
next_chapter.insert("title".to_owned(), n.to_json());
|
||||||
}
|
}
|
||||||
None => return Err(RenderError{ desc: "No title found for chapter in JSON data"})
|
None => return Err(RenderError{ desc: "No title found for chapter in JSON data"})
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
|
||||||
debug!("[*]: Inserting link: {:?}", link);
|
debug!("[*]: Inserting link: {:?}", link);
|
||||||
|
|
||||||
match link.to_str() {
|
match link.to_str() {
|
||||||
Some(l) => { next_chapter.insert("link".to_string(), l.to_json()); },
|
Some(l) => { next_chapter.insert("link".to_owned(), l.to_json()); },
|
||||||
None => return Err(RenderError{ desc: "Link could not converted to str"})
|
None => return Err(RenderError{ desc: "Link could not converted to str"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl HelperDef for RenderToc {
|
||||||
|
|
||||||
// Link
|
// Link
|
||||||
let path_exists = if let Some(path) = item.get("path") {
|
let path_exists = if let Some(path) = item.get("path") {
|
||||||
if path.len() > 0 {
|
if !path.is_empty() {
|
||||||
try!(rc.writer.write("<a href=\"".as_bytes()));
|
try!(rc.writer.write("<a href=\"".as_bytes()));
|
||||||
|
|
||||||
// Add link
|
// Add link
|
||||||
|
|
|
@ -72,7 +72,7 @@ pub fn create_path(path: &Path) -> Result<(), Box<Error>> {
|
||||||
|
|
||||||
for component in path.components() {
|
for component in path.components() {
|
||||||
|
|
||||||
let mut dir;
|
let dir;
|
||||||
match component {
|
match component {
|
||||||
Component::Normal(_) => { dir = PathBuf::from(component.as_os_str()); },
|
Component::Normal(_) => { dir = PathBuf::from(component.as_os_str()); },
|
||||||
Component::RootDir => {
|
Component::RootDir => {
|
||||||
|
|
Loading…
Reference in New Issue