From 7587f9798bfd4c2d4cf17e673643727caa329548 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Wed, 1 Feb 2023 13:33:35 -0330 Subject: input handling --- src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 527ddb8..e08796d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,13 +1,22 @@ pub mod ui; -enum Token { - Operand(f64), - Operator(Operator), -} - -enum Operator { +pub enum Operator { Add, Sub, Mul, Div, } + +impl Operator { + pub fn parse(c: char) -> Result { + match c { + '+' => Ok(Self::Add), + '-' => Ok(Self::Sub), + '*' => Ok(Self::Mul), + '/' => Ok(Self::Div), + _ => Err(ParseOperatorError(c)), + } + } +} + +pub struct ParseOperatorError(char); -- cgit v1.2.3