refactor: avoid extra owned string
I think this is more readable, too
This commit is contained in:
parent
acc49edd31
commit
5cdfbfea5e
1 changed files with 5 additions and 5 deletions
|
|
@ -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^"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue