diff options
| author | Fuwn <[email protected]> | 2023-04-16 02:07:06 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-16 02:07:06 +0000 |
| commit | ce929f2d0045560820f06d9c1b0768f2b401ff20 (patch) | |
| tree | cd29503376e1f1d6f89757d12e3f1c941339db52 | |
| parent | feat(ast): clean up from_*s for ast (diff) | |
| download | germ-ce929f2d0045560820f06d9c1b0768f2b401ff20.tar.xz germ-ce929f2d0045560820f06d9c1b0768f2b401ff20.zip | |
refactor(quick): optimise arguments
| -rw-r--r-- | crates/germ/src/quick.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/crates/germ/src/quick.rs b/crates/germ/src/quick.rs index 3ecf5a2..6bc5913 100644 --- a/crates/germ/src/quick.rs +++ b/crates/germ/src/quick.rs @@ -23,7 +23,10 @@ pub enum HeadingLevel { } #[must_use] -pub fn heading(text: &str, level: &HeadingLevel) -> String { +pub fn heading( + text: &(impl ToString + ?Sized), + level: &HeadingLevel, +) -> String { format!( "{} {}", match level { @@ -31,35 +34,42 @@ pub fn heading(text: &str, level: &HeadingLevel) -> String { HeadingLevel::Two => "##", HeadingLevel::Three => "###", }, - text + text.to_string() ) } #[must_use] -pub fn list_item(text: &str) -> String { format!("* {text}") } +pub fn list_item(text: &(impl ToString + ?Sized)) -> String { + format!("* {}", text.to_string()) +} #[must_use] -pub fn list_items(items: &[&str]) -> String { +pub fn list_items(items: &[&(impl ToString + ?Sized)]) -> String { items .iter() - .map(|item| list_item(item)) + .map(|item| list_item(&item.to_string())) .collect::<Vec<_>>() .join("\n") } #[must_use] -pub fn link(text: &str, location: Option<&str>) -> String { +pub fn link(text: &(impl ToString + ?Sized), location: Option<&str>) -> String { format!( "=> {}{}", - text, + text.to_string(), location.map_or_else(String::new, |l| format!(" {l}")) ) } #[must_use] -pub fn block_quote(text: &str) -> String { format!("> {text}") } +pub fn block_quote(text: &(impl ToString + ?Sized)) -> String { + format!("> {}", text.to_string()) +} #[must_use] -pub fn preformatted_text(text: &str, alt_text: Option<&str>) -> String { - format!("```{}\n{}\n```", alt_text.unwrap_or(""), text) +pub fn preformatted_text( + text: &(impl ToString + ?Sized), + alt_text: Option<&str>, +) -> String { + format!("```{}\n{}\n```", alt_text.unwrap_or(""), text.to_string()) } |