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

refactor(quick): optimise arguments

fuwn.net ce929f2d b52ad3f7

verified
+20 -10
+20 -10
crates/germ/src/quick.rs
··· 23 23 } 24 24 25 25 #[must_use] 26 - pub fn heading(text: &str, level: &HeadingLevel) -> String { 26 + pub fn heading( 27 + text: &(impl ToString + ?Sized), 28 + level: &HeadingLevel, 29 + ) -> String { 27 30 format!( 28 31 "{} {}", 29 32 match level { ··· 31 34 HeadingLevel::Two => "##", 32 35 HeadingLevel::Three => "###", 33 36 }, 34 - text 37 + text.to_string() 35 38 ) 36 39 } 37 40 38 41 #[must_use] 39 - pub fn list_item(text: &str) -> String { format!("* {text}") } 42 + pub fn list_item(text: &(impl ToString + ?Sized)) -> String { 43 + format!("* {}", text.to_string()) 44 + } 40 45 41 46 #[must_use] 42 - pub fn list_items(items: &[&str]) -> String { 47 + pub fn list_items(items: &[&(impl ToString + ?Sized)]) -> String { 43 48 items 44 49 .iter() 45 - .map(|item| list_item(item)) 50 + .map(|item| list_item(&item.to_string())) 46 51 .collect::<Vec<_>>() 47 52 .join("\n") 48 53 } 49 54 50 55 #[must_use] 51 - pub fn link(text: &str, location: Option<&str>) -> String { 56 + pub fn link(text: &(impl ToString + ?Sized), location: Option<&str>) -> String { 52 57 format!( 53 58 "=> {}{}", 54 - text, 59 + text.to_string(), 55 60 location.map_or_else(String::new, |l| format!(" {l}")) 56 61 ) 57 62 } 58 63 59 64 #[must_use] 60 - pub fn block_quote(text: &str) -> String { format!("> {text}") } 65 + pub fn block_quote(text: &(impl ToString + ?Sized)) -> String { 66 + format!("> {}", text.to_string()) 67 + } 61 68 62 69 #[must_use] 63 - pub fn preformatted_text(text: &str, alt_text: Option<&str>) -> String { 64 - format!("```{}\n{}\n```", alt_text.unwrap_or(""), text) 70 + pub fn preformatted_text( 71 + text: &(impl ToString + ?Sized), 72 + alt_text: Option<&str>, 73 + ) -> String { 74 + format!("```{}\n{}\n```", alt_text.unwrap_or(""), text.to_string()) 65 75 }