🦠 The Definitive Gemini Protocol Toolkit
gemini gemini-protocol gemtext parser zero-dependency toolkit ast converter html markdown cli networking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: various clippy lints

Fuwn 361374b8 82140f82

+38 -43
+1 -1
crates/germ/examples/html.rs
··· 47 47 48 48 fn main() { 49 49 std::fs::write( 50 - "examples/convert.html", 50 + "crates/germ/examples/convert.html", 51 51 germ::convert::from_string(EXAMPLE_GEMTEXT, &germ::convert::Target::HTML), 52 52 ) 53 53 .expect("could not write to file");
+1 -1
crates/germ/examples/markdown.rs
··· 47 47 48 48 fn main() { 49 49 std::fs::write( 50 - "examples/convert.md", 50 + "crates/germ/examples/convert.md", 51 51 germ::convert::from_string( 52 52 EXAMPLE_GEMTEXT, 53 53 &germ::convert::Target::Markdown,
+17 -20
crates/germ/src/ast/container.rs
··· 63 63 64 64 #[must_use] 65 65 pub fn to_gemtext(&self) -> String { 66 - let mut gemtext = "".to_string(); 66 + let mut gemtext = String::new(); 67 67 68 68 for node in &self.inner { 69 69 match node { 70 - Node::Text(text) => gemtext.push_str(&format!("{}\n", text)), 70 + Node::Text(text) => gemtext.push_str(&format!("{text}\n")), 71 71 Node::Link { 72 72 to, 73 73 text, ··· 77 77 to, 78 78 text 79 79 .clone() 80 - .map_or_else(|| "".to_string(), |text| format!(" {}", text)), 80 + .map_or_else(String::new, |text| format!(" {text}")), 81 81 )), 82 82 Node::Heading { 83 83 level, ··· 98 98 "{}\n", 99 99 items 100 100 .iter() 101 - .map(|i| format!("* {}", i)) 101 + .map(|i| format!("* {i}")) 102 102 .collect::<Vec<String>>() 103 103 .join("\n"), 104 104 )), 105 - Node::Blockquote(text) => gemtext.push_str(&format!("> {}\n", text)), 105 + Node::Blockquote(text) => gemtext.push_str(&format!("> {text}\n")), 106 106 Node::PreformattedText { 107 107 alt_text, 108 108 text, 109 109 } => 110 110 gemtext.push_str(&format!( 111 111 "```{}\n{}```\n", 112 - alt_text.clone().unwrap_or_else(|| "".to_string()), 112 + alt_text.clone().unwrap_or_default(), 113 113 text 114 114 )), 115 115 Node::Whitespace => gemtext.push('\n'), ··· 177 177 "#" => { 178 178 // If the Gemtext line starts with an "#", it is a heading, so let's 179 179 // find out how deep it goes. 180 - let level = match line.get(0..3) { 181 - Some(root) => 182 - if root.contains("###") { 183 - 3 184 - } else if root.contains("##") { 185 - 2 186 - } else if root.contains('#') { 187 - 1 188 - } else { 189 - 0 190 - }, 191 - None => 0, 192 - }; 180 + let level = line.get(0..3).map_or(0, |root| { 181 + if root.contains("###") { 182 + 3 183 + } else if root.contains("##") { 184 + 2 185 + } else { 186 + // Converting the boolean response of `contains` to an integer 187 + usize::from(root.contains('#')) 188 + } 189 + }); 193 190 194 191 nodes.push(Node::Heading { 195 192 level, ··· 263 260 if *in_preformatted { 264 261 // If we are in a preformatted line context, add the line to the 265 262 // preformatted blocks content and increment the line. 266 - preformatted.push_str(&format!("{}\n", line)); 263 + preformatted.push_str(&format!("{line}\n")); 267 264 268 265 if let Some(next_line) = lines.next() { 269 266 line = next_line;
+1 -1
crates/germ/src/ast/node.rs
··· 26 26 /// - [Gemtext Documentation](https://gemini.circumlunar.space/docs/gemtext.gmi) 27 27 /// - [Gemtext Cheatsheet](https://gemini.circumlunar.space/docs/cheatsheet.gmi). 28 28 /// - [Gemini Specification](https://gemini.circumlunar.space/docs/specification.gmi). 29 - #[derive(Debug, PartialEq, Clone)] 29 + #[derive(Debug, PartialEq, Clone, Eq)] 30 30 pub enum Node { 31 31 /// A text line 32 32 ///
+4 -4
crates/germ/src/convert/html.rs
··· 25 25 // this AST tree to an alternative markup format. 26 26 for node in source { 27 27 match node { 28 - Node::Text(text) => html.push_str(&format!("<p>{}</p>", text)), 28 + Node::Text(text) => html.push_str(&format!("<p>{text}</p>")), 29 29 Node::Link { 30 30 to, 31 31 text, ··· 56 56 "<ul>{}</ul>", 57 57 items 58 58 .iter() 59 - .map(|i| format!("<li>{}</li>", i)) 59 + .map(|i| format!("<li>{i}</li>")) 60 60 .collect::<Vec<String>>() 61 61 .join("\n") 62 62 )), 63 63 Node::Blockquote(text) => 64 - html.push_str(&format!("<blockquote>{}</blockquote>", text)), 64 + html.push_str(&format!("<blockquote>{text}</blockquote>")), 65 65 Node::PreformattedText { 66 66 text, .. 67 67 } => { 68 - html.push_str(&format!("<pre>{}</pre>", text)); 68 + html.push_str(&format!("<pre>{text}</pre>")); 69 69 } 70 70 Node::Whitespace => {} 71 71 }
+7 -7
crates/germ/src/convert/markdown.rs
··· 25 25 // this AST tree to an alternative markup format. 26 26 for node in source { 27 27 match node { 28 - Node::Text(text) => markdown.push_str(&format!("{}\n", text)), 28 + Node::Text(text) => markdown.push_str(&format!("{text}\n")), 29 29 Node::Link { 30 30 to, 31 31 text, 32 32 } => 33 - markdown.push_str(&*text.clone().map_or_else( 34 - || format!("<{}>\n", to), 35 - |text| format!("[{}]({})\n", text, to), 33 + markdown.push_str(&text.clone().map_or_else( 34 + || format!("<{to}>\n"), 35 + |text| format!("[{text}]({to})\n"), 36 36 )), 37 37 Node::Heading { 38 38 level, ··· 54 54 "{}\n", 55 55 items 56 56 .iter() 57 - .map(|i| format!("- {}", i)) 57 + .map(|i| format!("- {i}")) 58 58 .collect::<Vec<String>>() 59 59 .join("\n"), 60 60 )), 61 - Node::Blockquote(text) => markdown.push_str(&format!("> {}\n", text)), 61 + Node::Blockquote(text) => markdown.push_str(&format!("> {text}\n")), 62 62 Node::PreformattedText { 63 63 alt_text, 64 64 text, 65 65 } => { 66 66 markdown.push_str(&format!( 67 67 "```{}\n{}```\n", 68 - alt_text.clone().unwrap_or_else(|| "".to_string()), 68 + alt_text.clone().unwrap_or_default(), 69 69 text 70 70 )); 71 71 }
+1 -1
crates/germ/src/meta.rs
··· 52 52 parameters.reverse(); 53 53 54 54 if parameters.is_empty() { 55 - "".to_string() 55 + String::new() 56 56 } else { 57 57 format!("; {}", parameters.join("; ")) 58 58 }
+3 -3
crates/germ/src/quick.rs
··· 36 36 } 37 37 38 38 #[must_use] 39 - pub fn list_item(text: &str) -> String { format!("* {}", text) } 39 + pub fn list_item(text: &str) -> String { format!("* {text}") } 40 40 41 41 #[must_use] 42 42 pub fn list_items(items: &[&str]) -> String { ··· 52 52 format!( 53 53 "=> {}{}", 54 54 text, 55 - location.map_or_else(|| "".to_string(), |l| format!(" {}", l)) 55 + location.map_or_else(String::new, |l| format!(" {l}")) 56 56 ) 57 57 } 58 58 59 59 #[must_use] 60 - pub fn block_quote(text: &str) -> String { format!("> {}", text) } 60 + pub fn block_quote(text: &str) -> String { format!("> {text}") } 61 61 62 62 #[must_use] 63 63 pub fn preformatted_text(text: &str, alt_text: Option<&str>) -> String {
+1 -1
crates/germ/src/request.rs
··· 60 60 ))?; 61 61 let mut tls = rustls::Stream::new(&mut connection, &mut stream); 62 62 63 - tls.write_all(format!("{}\r\n", url).as_bytes())?; 63 + tls.write_all(format!("{url}\r\n").as_bytes())?; 64 64 65 65 let mut plain_text = Vec::new(); 66 66
+2 -4
crates/germ/src/request/status.rs
··· 28 28 /// assert_eq!(Status::from(10), Status::Input); 29 29 /// assert_eq!(i32::from(Status::Input), 10); 30 30 /// ``` 31 - #[derive(Debug, PartialEq, Clone)] 31 + #[derive(Debug, PartialEq, Clone, Eq)] 32 32 pub enum Status { 33 33 Input, 34 34 SensitiveInput, ··· 108 108 } 109 109 110 110 impl fmt::Display for Status { 111 - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 112 - write!(f, "{:?}", self) 113 - } 111 + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{self:?}") } 114 112 }