diff --git a/src/egui_app.rs b/src/egui_app.rs index c97eae8..8915fab 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -481,7 +481,7 @@ impl MathApp { ui.text_edit_singleline(&mut self.func_strs[i]); }); - let proc_func_str = process_func_str(self.func_strs[i].clone()); + let proc_func_str = process_func_str(&self.func_strs[i]); if configs_changed | integral_toggle | derivative_toggle | (proc_func_str != function.get_func_str()) diff --git a/src/parsing.rs b/src/parsing.rs index 5a26cd6..c85a345 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -68,7 +68,7 @@ EXTREMELY Janky function that tries to put asterisks in the proper places to be One limitation though, variables with multiple characters like `pi` cannot be multiplied (like `pipipipi` won't result in `pi*pi*pi*pi`). But that's such a niche use case (and that same thing could be done by using exponents) that it doesn't really matter. In the future I may want to completely rewrite this or implement this natively in exmex. */ -pub fn process_func_str(function_in: String) -> String { +pub fn process_func_str(function_in: &str) -> String { let function = function_in.replace("log10(", "log(").replace("pi", "π"); // pi -> π and log10 -> log let function_chars: Vec = function.chars().collect(); let mut output_string: String = String::new(); @@ -186,7 +186,7 @@ pub fn test_func(function_string: &str) -> Option { /// `test_func` #[cfg(test)] fn test_func_helper(function_string: &str) -> Option { - test_func(&process_func_str(function_string.to_string())) + test_func(&process_func_str(function_string)) } /// Tests to make sure functions are parsed correctly @@ -210,7 +210,7 @@ fn test_func_test() { /// Helps with tests of `process_func_str` #[cfg(test)] fn test_process_helper(input: &str, expected: &str) { - assert_eq!(&process_func_str(input.to_string()), expected); + assert_eq!(&process_func_str(input), expected); } /// Tests to make sure my cursed function works as intended