From 1f6fa5a58030f4ff2adde61e7652d1956e407510 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 9 Feb 2023 15:26:30 -0330 Subject: simplify Function method and rename Calculator method --- src/input.rs | 4 ++-- src/lib.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/input.rs b/src/input.rs index a80ce11..e7783fb 100644 --- a/src/input.rs +++ b/src/input.rs @@ -33,7 +33,7 @@ impl Calculator { KeyCode::Enter if self.input_buffer.len() > 0 => { if let Ok(func) = Function::parse(&self.input_buffer) { if let Some(f) = self.stack.pop() { - self.stack.push(func.func()(f)); + self.stack.push(func.call_on(f)); } } else { self.stack.push(self.input_buffer.parse::().unwrap()); @@ -56,7 +56,7 @@ impl Calculator { } else if let Ok(op) = Operator::parse(c) { self.stack.push(self.input_buffer.parse::().unwrap()); self.input_buffer = String::new(); - self.op(op); + self.perform_operation(op); } else { self.input_buffer.push(c); } diff --git a/src/lib.rs b/src/lib.rs index a7186e6..a871788 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ pub struct Calculator { } impl Calculator { - fn op(&mut self, op: Operator) { + fn perform_operation(&mut self, op: Operator) { let rhs = match self.stack.pop() { Some(f) => f, None => { @@ -70,11 +70,11 @@ impl Function { } } - fn func(&self) -> impl Fn(f64) -> f64 { + fn call_on(&self, f: f64) -> f64 { match self { - Self::Sin => |f: f64| f.sin(), - Self::Cos => |f: f64| f.cos(), - Self::Tan => |f: f64| f.tan(), + Self::Sin => f.sin(), + Self::Cos => f.cos(), + Self::Tan => f.tan(), } } } -- cgit v1.2.3