diff --git a/.clippy.toml b/.clippy.toml index 4bda813..ee470c2 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -2,3 +2,4 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true single-char-binding-names-threshold = 2 upper-case-acronyms-aggressive = true +allow-indexing-slicing-in-tests = true diff --git a/.justfile b/.justfile index 4dc2004..6c04fc5 100644 --- a/.justfile +++ b/.justfile @@ -96,7 +96,7 @@ alias f := format # Lint [group: 'develop'] lint: - cargo +nightly clippy + cargo +nightly clippy --timings --all-targets alias l := lint @@ -228,9 +228,10 @@ alias fc := format-assess # Assess production lints [group: 'assess'] lint-assess: - cargo +nightly clippy -- \ - -D clippy::dbg_macro -D clippy::use_debug \ + cargo +nightly clippy --timings -- \ -D clippy::print_stdout -D clippy::print_stderr \ + -D clippy::dbg_macro -D clippy::use_debug + cargo +nightly clippy --timings --all-targets -- \ -D clippy::todo -D clippy::unimplemented -D clippy::unreachable alias la := lint-assess diff --git a/Cargo.toml b/Cargo.toml index de8f7a3..8b52c6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -211,7 +211,6 @@ shadow_reuse = "warn" shadow_same = "warn" shadow_unrelated = "warn" should_panic_without_expect = "warn" -similar_names = "warn" single_char_pattern = "warn" single_match_else = "warn" single_option_map = "warn" diff --git a/src/graph.rs b/src/graph.rs index 7cdb7b6..7e24eb0 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -721,8 +721,8 @@ mod tests { .unwrap(); graph.modulate(); - let node = graph.nodes.get("Node").unwrap(); - let connection = node.connections.get("Nowhere").unwrap(); + let node = &graph.nodes["Node"]; + let connection = &node.connections["Nowhere"]; assert!(connection.detached); } @@ -743,8 +743,8 @@ mod tests { .unwrap(); graph.modulate(); - let node = graph.nodes.get("NodeOne").unwrap(); - let connection = node.connections.get("NodeTwo").unwrap(); + let node = &graph.nodes["NodeOne"]; + let connection = &node.connections["NodeTwo"]; println!("{connection:#?}"); assert!(!connection.detached); } @@ -763,10 +763,10 @@ mod tests { .unwrap(); graph.modulate(); - let n01 = graph.nodes.get("n01").unwrap(); - let n02 = graph.nodes.get("n02").unwrap(); - let n01_to_n02 = n01.connections.get("n02").unwrap(); - let n02_to_n03 = n02.connections.get("n03").unwrap(); + let n01 = &graph.nodes["n01"]; + let n02 = &graph.nodes["n02"]; + let n01_to_n02 = &n01.connections["n02"]; + let n02_to_n03 = &n02.connections["n03"]; assert_eq!(n01_to_n02.from, "n01"); assert_eq!(n01_to_n02.to, "n02"); @@ -793,16 +793,16 @@ mod tests { .unwrap(); graph.modulate(); - let n01 = graph.nodes.get("n01").unwrap(); - let n02 = graph.nodes.get("n02").unwrap(); - let n04 = graph.nodes.get("n04").unwrap(); + let n01 = &graph.nodes["n01"]; + let n02 = &graph.nodes["n02"]; + let n04 = &graph.nodes["n04"]; - let n01_to_n02 = n01.connections.get("n02").unwrap(); - let n01_to_n03 = n01.connections.get("n03").unwrap(); - let n01_to_n04 = n01.connections.get("n04").unwrap(); + let n01_to_n02 = &n01.connections["n02"]; + let n01_to_n03 = &n01.connections["n03"]; + let n01_to_n04 = &n01.connections["n04"]; - let n04_to_n01 = n04.connections.get("n01").unwrap(); - let n04_to_n03 = n04.connections.get("n03").unwrap(); + let n04_to_n01 = &n04.connections["n01"]; + let n04_to_n03 = &n04.connections["n03"]; assert_eq!(n01_to_n02.from, "n01"); assert_eq!(n01_to_n02.to, "n02"); @@ -861,8 +861,8 @@ mod tests { .unwrap(); graph.modulate(); - assert!(graph.nodes.get("n01").unwrap().summary.contains(text)); - assert!(graph.nodes.get("n01").unwrap().text.contains(text)); + assert!(&graph.nodes["n01"].summary.contains(text)); + assert!(&graph.nodes["n01"].text.contains(text)); } #[test] @@ -881,8 +881,8 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, summary); - assert!(graph.nodes.get("n01").unwrap().text.contains(text)); + assert_eq!(&graph.nodes["n01"].summary, summary); + assert!(&graph.nodes["n01"].text.contains(text)); } #[test] @@ -900,7 +900,7 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, first_sentence); + assert_eq!(&graph.nodes["n01"].summary, first_sentence); } #[test] @@ -919,7 +919,7 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, first_paragraph); + assert_eq!(&graph.nodes["n01"].summary, first_paragraph); } #[test] @@ -948,7 +948,7 @@ mod tests { .unwrap(); graph.modulate(); - assert_eq!(graph.nodes.get("n01").unwrap().summary, summary); + assert_eq!(graph.nodes["n01"].summary, summary); } #[test] @@ -967,9 +967,9 @@ mod tests { .unwrap(); graph.modulate(); - let n1_to_n2 = graph.nodes.get("n1").unwrap().connections.get("n2"); + let n1_to_n2 = &graph.nodes["n1"].connections.get("n2"); - let n2_to_n0 = graph.nodes.get("n2").unwrap().connections.get("n0"); + let n2_to_n0 = &graph.nodes["n2"].connections.get("n0"); println!("{n1_to_n2:#?}"); println!("{n2_to_n0:#?}"); @@ -991,8 +991,8 @@ mod tests { graph.modulate(); assert_eq!(graph.stats.detached_total, 2); - assert_eq!(*graph.stats.detached.get("anchor").unwrap(), 1); - assert_eq!(*graph.stats.detached.get("this one").unwrap(), 1); + assert_eq!(graph.stats.detached["anchor"], 1); + assert_eq!(graph.stats.detached["this one"], 1); } #[test] @@ -1008,7 +1008,7 @@ mod tests { graph.modulate(); assert_eq!(graph.stats.detached_total, 2); - assert_eq!(*graph.stats.detached.get("anchor").unwrap(), 2); + assert_eq!(graph.stats.detached["anchor"], 2); } #[test] @@ -1295,7 +1295,7 @@ mod tests { assert!(!format!("{none}").contains("exact")); let some = QueryResult { - node: Some(node.clone()), + node: Some(node), exact: false, redirect: false, }; diff --git a/src/graph/meta.rs b/src/graph/meta.rs index 5df4db0..4d4f56e 100644 --- a/src/graph/meta.rs +++ b/src/graph/meta.rs @@ -600,7 +600,6 @@ mod tests { assert!( validation_error .message - .clone() .unwrap() .contains("Splits to three elements: false") ); diff --git a/src/router/handlers/mime.rs b/src/router/handlers/mime.rs index 476ccc9..9d108e5 100644 --- a/src/router/handlers/mime.rs +++ b/src/router/handlers/mime.rs @@ -102,39 +102,18 @@ impl Mime { } } - pub fn kind(&self) -> Result { - let string = String::from(self.clone()); - let mut parts = string.split('/'); - let first_opt = parts.next(); - let second_opt = parts.next(); - if let Some(first) = first_opt - && let Some(second) = second_opt - { - if first == "application" { - if second == "toml" || second == "xml" || second == "json" { - Ok(Kind::Text) - } else if second == "pdf" - || second == "epub" - || second == "epub+zip" - || second == "octet-stream" - { - Ok(Kind::Blob) - } else { - Err(format!( - "Unexpected application kind for mimetype {string}" - )) - } - } else if first == "text" { - Ok(Kind::Text) - } else if first == "font" { - Ok(Kind::Font) - } else if first == "image" { - Ok(Kind::Image) - } else { - Err(format!("Could not determine a kind for mimetype {string}")) - } - } else { - Err(format!("Mimetype {string} couldn't be split on a slash")) + /// Returns one of four kind of mimetypes among text, font, image and blob. + /// + /// This is mainly used when serving assets through the `fixed` module in + /// order to determine what `Asset` field to use when assemblimg a response + /// body. + pub const fn kind(&self) -> Kind { + use Mime::*; + match self { + Txt | Csv | Css | Toml | Xml | Json | Js | Svg => Kind::Text, + Ttf | Otf | Woff | Woff2 => Kind::Font, + Ico | Jpeg | Png | Apng | Gif | Webp | Avif => Kind::Image, + Pdf | Epub | Unknown => Kind::Blob, } } } diff --git a/src/syntax/content/parser/lexeme.rs b/src/syntax/content/parser/lexeme.rs index d0c1e3e..495b27b 100644 --- a/src/syntax/content/parser/lexeme.rs +++ b/src/syntax/content/parser/lexeme.rs @@ -286,7 +286,7 @@ mod tests { fn first_segment() { let payload = "nhNc fGev QnGW E4hj ExyZ"; let lexeme = Lexeme::new(payload, "", ""); - assert_eq!(lexeme.clone().first_segment(), Some(String::from("nhNc"))); + assert_eq!(lexeme.first_segment(), Some(String::from("nhNc"))); } #[test] @@ -381,8 +381,8 @@ mod tests { let lexemes = Lexeme::collect(&input); let first = lexemes.first().unwrap(); - let second = lexemes.get(1).unwrap(); - let third = lexemes.get(2).unwrap(); + let second = &lexemes[1]; + let third = &lexemes[2]; let last = lexemes.last().unwrap(); assert_eq!( diff --git a/src/syntax/content/parser/token/anchor.rs b/src/syntax/content/parser/token/anchor.rs index 12ee711..54639df 100644 --- a/src/syntax/content/parser/token/anchor.rs +++ b/src/syntax/content/parser/token/anchor.rs @@ -216,7 +216,7 @@ mod tests { anchor.external = true; assert_eq!( - format!("{}", Token::Anchor(Box::new(anchor.clone()))), + format!("{}", Token::Anchor(Box::new(anchor))), "Tk:Anchor 'wPVo1 0OmYm' -> \"M1UEp 1gbfr\" \ +Leading +Balanced +External", ); diff --git a/src/syntax/content/parser/token/bold.rs b/src/syntax/content/parser/token/bold.rs index 6ef5bd3..6053ad7 100644 --- a/src/syntax/content/parser/token/bold.rs +++ b/src/syntax/content/parser/token/bold.rs @@ -60,10 +60,7 @@ mod tests { assert_eq!(format!("{}", Token::Bold(bold.clone())), "Tk:Bold [open]"); bold.open = false; - assert_eq!( - format!("{}", Token::Bold(bold.clone())), - "Tk:Bold [closed]" - ); + assert_eq!(format!("{}", Token::Bold(bold)), "Tk:Bold [closed]"); } #[test] diff --git a/src/syntax/content/parser/token/checkbox.rs b/src/syntax/content/parser/token/checkbox.rs index c2597b7..61bc61a 100644 --- a/src/syntax/content/parser/token/checkbox.rs +++ b/src/syntax/content/parser/token/checkbox.rs @@ -64,7 +64,7 @@ mod tests { checkbox.checked = false; assert_eq!( - format!("{}", Token::CheckBox(checkbox.clone())), + format!("{}", Token::CheckBox(checkbox)), "Tk:CheckBox [empty]" ); } diff --git a/src/syntax/content/parser/token/code.rs b/src/syntax/content/parser/token/code.rs index a6f6977..d11d5fe 100644 --- a/src/syntax/content/parser/token/code.rs +++ b/src/syntax/content/parser/token/code.rs @@ -60,9 +60,6 @@ mod tests { assert_eq!(format!("{}", Token::Code(code.clone())), "Tk:Code [open]"); code.open = false; - assert_eq!( - format!("{}", Token::Code(code.clone())), - "Tk:Code [closed]" - ); + assert_eq!(format!("{}", Token::Code(code)), "Tk:Code [closed]"); } } diff --git a/src/syntax/content/parser/token/item.rs b/src/syntax/content/parser/token/item.rs index a0b8321..02b34ee 100644 --- a/src/syntax/content/parser/token/item.rs +++ b/src/syntax/content/parser/token/item.rs @@ -80,7 +80,7 @@ mod tests { ); item.depth = None; assert_eq!( - format!("{}", Token::Item(item.clone())), + format!("{}", Token::Item(item)), "Tk:Item [] dRMy4" ); } diff --git a/src/syntax/content/parser/token/linebreak.rs b/src/syntax/content/parser/token/linebreak.rs index 023efd7..ea20a74 100644 --- a/src/syntax/content/parser/token/linebreak.rs +++ b/src/syntax/content/parser/token/linebreak.rs @@ -28,7 +28,6 @@ mod tests { #[test] fn token_display() { - let linebreak = LineBreak::default(); - assert_eq!(format!("{}", Token::LineBreak(linebreak)), "Tk:LineBreak"); + assert_eq!(format!("{}", Token::LineBreak(LineBreak)), "Tk:LineBreak"); } } diff --git a/src/syntax/content/parser/token/literal.rs b/src/syntax/content/parser/token/literal.rs index d812a64..e165d73 100644 --- a/src/syntax/content/parser/token/literal.rs +++ b/src/syntax/content/parser/token/literal.rs @@ -43,9 +43,6 @@ mod tests { ); literal.text = String::from("TjY02"); - assert_eq!( - format!("{}", Token::Literal(literal.clone())), - "Tk:Literal TjY02" - ); + assert_eq!(format!("{}", Token::Literal(literal)), "Tk:Literal TjY02"); } } diff --git a/src/syntax/content/parser/token/oblique.rs b/src/syntax/content/parser/token/oblique.rs index fa12ba2..7e4baf1 100644 --- a/src/syntax/content/parser/token/oblique.rs +++ b/src/syntax/content/parser/token/oblique.rs @@ -64,7 +64,7 @@ mod tests { oblique.open = false; assert_eq!( - format!("{}", Token::Oblique(oblique.clone())), + format!("{}", Token::Oblique(oblique)), "Tk:Oblique [closed]" ); } diff --git a/src/syntax/content/parser/token/paragraph.rs b/src/syntax/content/parser/token/paragraph.rs index ab635d2..3512320 100644 --- a/src/syntax/content/parser/token/paragraph.rs +++ b/src/syntax/content/parser/token/paragraph.rs @@ -89,7 +89,7 @@ mod tests { paragraph.open = None; assert_eq!( - format!("{}", Token::Paragraph(paragraph.clone())), + format!("{}", Token::Paragraph(paragraph)), "Tk:Paragraph [unknown]" ); } diff --git a/src/syntax/content/parser/token/preformat.rs b/src/syntax/content/parser/token/preformat.rs index 1ca0128..666ad68 100644 --- a/src/syntax/content/parser/token/preformat.rs +++ b/src/syntax/content/parser/token/preformat.rs @@ -85,7 +85,7 @@ mod tests { preformat.open = None; assert_eq!( - format!("{}", Token::PreFormat(preformat.clone())), + format!("{}", Token::PreFormat(preformat)), "Tk:PreFormat [unknown]" ); } diff --git a/src/syntax/content/parser/token/strike.rs b/src/syntax/content/parser/token/strike.rs index 4aadc56..2d98822 100644 --- a/src/syntax/content/parser/token/strike.rs +++ b/src/syntax/content/parser/token/strike.rs @@ -62,10 +62,7 @@ mod tests { ); strike.open = false; - assert_eq!( - format!("{}", Token::Strike(strike.clone())), - "Tk:Strike [closed]" - ); + assert_eq!(format!("{}", Token::Strike(strike)), "Tk:Strike [closed]"); } #[test] diff --git a/src/syntax/content/parser/token/underline.rs b/src/syntax/content/parser/token/underline.rs index bf60f1d..e8e2668 100644 --- a/src/syntax/content/parser/token/underline.rs +++ b/src/syntax/content/parser/token/underline.rs @@ -66,7 +66,7 @@ mod tests { underline.open = false; assert_eq!( - format!("{}", Token::Underline(underline.clone())), + format!("{}", Token::Underline(underline)), "Tk:Underline [closed]" ); }