From 5c909bd08e447b266d4e71b324d3e9cd78d2429d Mon Sep 17 00:00:00 2001 From: pmeinhardt Date: Fri, 24 May 2024 15:00:53 +0200 Subject: [PATCH] =?UTF-8?q?Use=20fold=20to=20replace=20all=20placeholders?= =?UTF-8?q?=20in=20template=20=F0=9F=AA=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 279d8d8..a6d568e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,14 +60,10 @@ fn convert(input: &str, dangerous: bool) -> Result { } fn render(template: &str, values: &HashMap<&str, &str>) -> String { - let mut result = String::from(template); - - for (key, value) in values { + return values.iter().fold(String::from(template), |result, (key, value)| { let pattern = format!("{{{{ {key} }}}}"); - result = result.replace(&pattern, value) - } - - result + result.replace(&pattern, value) + }) } fn main() -> Result<()> {