summaryrefslogtreecommitdiffstats
path: root/src/book
diff options
context:
space:
mode:
authorlzutao <taolzu@gmail.com>2019-05-07 01:20:58 +0700
committerDylan DPC <dylan.dpc@gmail.com>2019-05-06 20:20:58 +0200
commitab7802a9a900e4746b02772cc1901db552259369 (patch)
tree7ebdd51849d4640651f780e952da7cffa6de92df /src/book
parent345acb85973e162a7d8b11662873ef87eed4154b (diff)
Fix most of clippy warnings (#914)
* Fix clippy: cast_lossless * Fix clippy: match_ref_pats * Fix clippy: extra_unused_lifetimes * Fix clippy: needless_lifetimes * Fix clippy: new_without_default * Fix clippy: or_fun_call * Fix clippy: should_implement_trait * Fix clippy: redundant_closure * Fix clippy: const_static_lifetime * Fix clippy: redundant_pattern_matching * Fix clippy: unused_io_amount * Fix clippy: string_lit_as_bytes * Fix clippy: needless_update * Fix clippy: blacklisted_name * Fix clippy: collapsible_if * Fix clippy: match_wild_err_arm * Fix clippy: single_match * Fix clippy: useless_vec * Fix clippy: single_char_pattern * Fix clippy: float_cmp * Fix clippy: approx_constant
Diffstat (limited to 'src/book')
-rw-r--r--src/book/book.rs8
-rw-r--r--src/book/mod.rs20
2 files changed, 15 insertions, 13 deletions
diff --git a/src/book/book.rs b/src/book/book.rs
index 62af2d92..c98c03c2 100644
--- a/src/book/book.rs
+++ b/src/book/book.rs
@@ -116,7 +116,7 @@ where
I: IntoIterator<Item = &'a mut BookItem>,
{
for item in items {
- if let &mut BookItem::Chapter(ref mut ch) = item {
+ if let BookItem::Chapter(ch) = item {
for_each_mut(func, &mut ch.sub_items);
}
@@ -301,7 +301,7 @@ mod tests {
use std::io::Write;
use tempfile::{Builder as TempFileBuilder, TempDir};
- const DUMMY_SRC: &'static str = "
+ const DUMMY_SRC: &str = "
# Dummy Chapter
this is some dummy text.
@@ -317,7 +317,7 @@ And here is some \
let chapter_path = temp.path().join("chapter_1.md");
File::create(&chapter_path)
.unwrap()
- .write(DUMMY_SRC.as_bytes())
+ .write_all(DUMMY_SRC.as_bytes())
.unwrap();
let link = Link::new("Chapter 1", chapter_path);
@@ -333,7 +333,7 @@ And here is some \
File::create(&second_path)
.unwrap()
- .write_all("Hello World!".as_bytes())
+ .write_all(b"Hello World!")
.unwrap();
let mut second = Link::new("Nested Chapter 1", &second_path);
diff --git a/src/book/mod.rs b/src/book/mod.rs
index 5002c353..41ae50d9 100644
--- a/src/book/mod.rs
+++ b/src/book/mod.rs
@@ -16,6 +16,7 @@ pub use self::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
+use std::string::ToString;
use tempfile::Builder as TempFileBuilder;
use toml::Value;
@@ -346,7 +347,7 @@ impl MDBook {
fn determine_renderers(config: &Config) -> Vec<Box<Renderer>> {
let mut renderers: Vec<Box<Renderer>> = Vec::new();
- if let Some(output_table) = config.get("output").and_then(|o| o.as_table()) {
+ if let Some(output_table) = config.get("output").and_then(Value::as_table) {
for (key, table) in output_table.iter() {
// the "html" backend has its own Renderer
if key == "html" {
@@ -386,7 +387,7 @@ fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
preprocessors.extend(default_preprocessors());
}
- if let Some(preprocessor_table) = config.get("preprocessor").and_then(|v| v.as_table()) {
+ if let Some(preprocessor_table) = config.get("preprocessor").and_then(Value::as_table) {
for key in preprocessor_table.keys() {
match key.as_ref() {
"links" => preprocessors.push(Box::new(LinkPreprocessor::new())),
@@ -405,8 +406,8 @@ fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
fn interpret_custom_preprocessor(key: &str, table: &Value) -> Box<CmdPreprocessor> {
let command = table
.get("command")
- .and_then(|c| c.as_str())
- .map(|s| s.to_string())
+ .and_then(Value::as_str)
+ .map(ToString::to_string)
.unwrap_or_else(|| format!("mdbook-{}", key));
Box::new(CmdPreprocessor::new(key.to_string(), command.to_string()))
@@ -417,8 +418,8 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
// prepended by "mdbook-"
let table_dot_command = table
.get("command")
- .and_then(|c| c.as_str())
- .map(|s| s.to_string());
+ .and_then(Value::as_str)
+ .map(ToString::to_string);
let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{}", key));
@@ -443,7 +444,7 @@ fn preprocessor_should_run(preprocessor: &Preprocessor, renderer: &Renderer, cfg
if let Some(Value::Array(ref explicit_renderers)) = cfg.get(&key) {
return explicit_renderers
.iter()
- .filter_map(|val| val.as_str())
+ .filter_map(Value::as_str)
.any(|name| name == renderer_name);
}
@@ -453,6 +454,7 @@ fn preprocessor_should_run(preprocessor: &Preprocessor, renderer: &Renderer, cfg
#[cfg(test)]
mod tests {
use super::*;
+ use std::str::FromStr;
use toml::value::{Table, Value};
#[test]
@@ -570,9 +572,9 @@ mod tests {
let html = cfg
.get_preprocessor("links")
.and_then(|links| links.get("renderers"))
- .and_then(|renderers| renderers.as_array())
+ .and_then(Value::as_array)
.and_then(|renderers| renderers.get(0))
- .and_then(|renderer| renderer.as_str())
+ .and_then(Value::as_str)
.unwrap();
assert_eq!(html, "html");
let html_renderer = HtmlHandlebars::default();