refactor: avoid extra owned string

I think this is more readable, too
This commit is contained in:
electria 2026-10-09 18:53:02 -07:00
commit 5cdfbfea5e
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -3,14 +3,14 @@ use rug::Float;
use crate::nodes::{self, Error}; use crate::nodes::{self, Error};
pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> { pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
let (prefix, input) = input let (prefix, deliminator, input) = input
.rsplit_once('=') .rsplit_once('=')
.map(|(p, i)| (p.to_owned() + "= ", i)) .map(|(p, i)| (p, "= ", i))
.unwrap_or_else(|| { .unwrap_or_else(|| {
input input
.rsplit_once('&') .rsplit_once('&')
.map(|(p, i)| (p.to_owned() + "& ", i)) .map(|(p, i)| (p, "& ", i))
.unwrap_or((String::new(), input)) .unwrap_or(("", "", input))
}); });
// no need to remove the character here, // no need to remove the character here,
@ -33,7 +33,7 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
}); });
Ok(format!( Ok(format!(
"{prefix}{result:.display_digits$}{}", "{prefix}{deliminator}{result:.display_digits$}{}",
if should_add_back_backslash { " \\" } else { "" } if should_add_back_backslash { " \\" } else { "" }
) )
.replace('e', " * 10^")) .replace('e', " * 10^"))