From 5cdfbfea5ece7ec3665bc2639f118d7eb93d09f0 Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 9 Oct 2026 18:53:02 -0700 Subject: [PATCH] refactor: avoid extra owned string I think this is more readable, too --- src/formatting.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index fff48dc..7c207f5 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -3,14 +3,14 @@ use rug::Float; use crate::nodes::{self, Error}; pub fn pretty_eval(input: &str, max_digits: usize) -> Result { - let (prefix, input) = input + let (prefix, deliminator, input) = input .rsplit_once('=') - .map(|(p, i)| (p.to_owned() + "= ", i)) + .map(|(p, i)| (p, "= ", i)) .unwrap_or_else(|| { input .rsplit_once('&') - .map(|(p, i)| (p.to_owned() + "& ", i)) - .unwrap_or((String::new(), input)) + .map(|(p, i)| (p, "& ", i)) + .unwrap_or(("", "", input)) }); // no need to remove the character here, @@ -33,7 +33,7 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result { }); Ok(format!( - "{prefix}{result:.display_digits$}{}", + "{prefix}{deliminator}{result:.display_digits$}{}", if should_add_back_backslash { " \\" } else { "" } ) .replace('e', " * 10^"))