From 564f95aa3277aed306bc2a4f13d1dd5002f397c3 Mon Sep 17 00:00:00 2001 From: electria Date: Sun, 4 Oct 2026 16:34:21 -0700 Subject: [PATCH] refactor: use Node::from from parsed Floats this is a little nicer, hopefully it has no perf penalty --- src/nodes/parse.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/nodes/parse.rs b/src/nodes/parse.rs index 22a0518..4a20221 100644 --- a/src/nodes/parse.rs +++ b/src/nodes/parse.rs @@ -1,9 +1,9 @@ use core::f64; use std::str::FromStr; -use rug::{Float, float::ParseFloatError, ops::CompleteRound}; +use rug::{Float, float::ParseFloatError}; -use crate::nodes::{Function, Node, Nodes, Operator, PREC}; +use crate::nodes::{Function, Node, Nodes, Operator}; impl Node { fn from_name(s: &str) -> Result { @@ -124,15 +124,10 @@ impl FromStr for Nodes { && !(c == 'e' && filtered_string.chars().nth(i + 1).is_some_and(|c| c == '-')) && !(c == '-' && filtered_string.chars().nth(i - 1).is_some_and(|c| c == 'e')) { - nodes.push(Node::Number( - Float::parse(&filtered_string[start_index..i]) - .map_err(|e| { - Error::NumberParsing( - filtered_string[start_index..i].to_owned(), - e, - ) - })? - .complete(PREC), + nodes.push(Node::from( + Float::parse(&filtered_string[start_index..i]).map_err(|e| { + Error::NumberParsing(filtered_string[start_index..i].to_owned(), e) + })?, )); state = ParsingState::Start; @@ -182,12 +177,10 @@ impl FromStr for Nodes { if matches!(nodes.last(), Some(Node::ParenthesisEnd)) { nodes.push(Node::Operator(Default::default())); } - nodes.push(Node::Number( - Float::parse(&filtered_string[start_index..i]) - .map_err(|e| { - Error::NumberParsing(filtered_string[start_index..i].to_owned(), e) - })? - .complete(PREC), + nodes.push(Node::from( + Float::parse(&filtered_string[start_index..i]).map_err(|e| { + Error::NumberParsing(filtered_string[start_index..i].to_owned(), e) + })?, )); } }