diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-11 09:14:33 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-11 09:14:33 +0200 |
commit | 7ad659a6ad899ef91225331cfc8aac06e85c6389 (patch) | |
tree | 0e4ead7b03e87cc289178456dabfa5f5099a034c | |
parent | 0dd00fb6a04a68fd0e634cbf4c7cefa245204bb8 (diff) | |
download | pandoc-filter-diagram-7ad659a6ad899ef91225331cfc8aac06e85c6389.tar.gz |
chore: tidy up based on clippy suggestions
Sponsored-by: author
-rw-r--r-- | src/lib.rs | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -74,8 +74,8 @@ pub enum DiagramError { type Svg = Vec<u8>; -impl DiagramFilter { - pub fn new() -> Self { +impl Default for DiagramFilter { + fn default() -> Self { Self { dot: PathBuf::from("dot"), roadmap_width: 50, @@ -83,6 +83,12 @@ impl DiagramFilter { plantuml_jar: PathBuf::from("/usr/share/plantuml/plantuml.jar"), } } +} + +impl DiagramFilter { + pub fn new() -> Self { + Self::default() + } pub fn dot_path<P>(&mut self, path: P) -> &mut Self where @@ -119,8 +125,7 @@ impl DiagramFilter { } fn error_block(&self, error: DiagramError) -> Block { - let msg = format!("ERROR: {}", error.to_string()); - let msg = Inline::Str(String::from(msg)); + let msg = Inline::Str(format!("ERROR: {}", error.to_string())); let msg = vec![Inline::Strong(vec![msg])]; Block::Para(msg) } @@ -221,7 +226,7 @@ fn filter_via( let status = if let Some(code) = output.status.code() { format!("{}", code) } else { - format!("terminated by signal") + String::from("terminated by signal") }; let stderr = String::from_utf8_lossy(&output.stderr); Err(DiagramError::HelperFailed( @@ -248,7 +253,7 @@ fn filter_via( impl MutVisitor for DiagramFilter { fn visit_block(&mut self, block: &mut Block) { match block { - Block::CodeBlock((_id, classes, _kv), text) => match DiagramKind::from(&classes) { + Block::CodeBlock((_id, classes, _kv), text) => match DiagramKind::from(classes) { DiagramKind::GraphvizDot => match self.dot_to_svg(text) { Err(err) => *block = self.error_block(err), Ok(svg) => *block = self.svg_block(&svg), @@ -285,7 +290,7 @@ enum DiagramKind { } impl DiagramKind { - fn from(classes: &Vec<String>) -> Self { + fn from(classes: &[String]) -> Self { if has_class(classes, "pikchr") { Self::Pikchr } else if has_class(classes, "dot") { @@ -302,6 +307,6 @@ impl DiagramKind { } } -fn has_class(classes: &Vec<String>, wanted: &str) -> bool { +fn has_class(classes: &[String], wanted: &str) -> bool { classes.iter().any(|s| s == wanted) } |