aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 951a128..a7186e6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -8,7 +8,7 @@ pub struct Calculator {
}
impl Calculator {
- fn perform_operation(&mut self, op: Operator) {
+ fn op(&mut self, op: Operator) {
let rhs = match self.stack.pop() {
Some(f) => f,
None => {
@@ -54,6 +54,33 @@ impl Operator {
pub struct ParseOperatorError(char);
+enum Function {
+ Sin,
+ Cos,
+ Tan,
+}
+
+impl Function {
+ fn parse(s: &str) -> Result<Self, ParseFunctionError> {
+ match s {
+ "sin" => Ok(Self::Sin),
+ "cos" => Ok(Self::Cos),
+ "tan" => Ok(Self::Tan),
+ _ => Err(ParseFunctionError(s.to_string())),
+ }
+ }
+
+ fn func(&self) -> impl Fn(f64) -> f64 {
+ match self {
+ Self::Sin => |f: f64| f.sin(),
+ Self::Cos => |f: f64| f.cos(),
+ Self::Tan => |f: f64| f.tan(),
+ }
+ }
+}
+
+struct ParseFunctionError(String);
+
pub enum Signal {
None,
Exit,