From 5983d9b5873a1f240f4a6a4489a6c31ea8e0faf4 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Wed, 14 Feb 2024 23:32:57 +0100 Subject: [PATCH] do not clone `EnvVar` fields for `Display` --- src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 529da27..2728cbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,14 +109,18 @@ impl EnvVar { } impl Display for EnvVar { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let key = self.name.clone(); - match self.value.clone() { - Value::Null => write!(f, "{key}=null"), - Value::Bool(bool) => write!(f, "{key}={bool}",), - Value::Number(number) => write!(f, "{key}={number}"), - Value::String(string) => write!(f, r#"{key}="{}""#, string.replace('"', r#"\""#)), - _ => write!(f, ""), + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self.value { + Value::Null => write!(fmt, "{key}=null", key = self.name), + Value::Bool(bool) => write!(fmt, "{key}={bool}", key = self.name), + Value::Number(ref number) => write!(fmt, "{key}={number}", key = self.name), + Value::String(ref string) => write!( + fmt, + r#"{key}="{value}""#, + key = self.name, + value = string.replace('"', r#"\""#) + ), + _ => write!(fmt, ""), } } }