diff --git a/src/renderer/context_element.rs b/src/renderer/context_element.rs index fe78473..56d194c 100644 --- a/src/renderer/context_element.rs +++ b/src/renderer/context_element.rs @@ -5,6 +5,10 @@ use crate::renderer::errors::WalkError; use crate::renderer::DustRenderer; use std::any::Any; use std::ops::Add; +use std::ops::Div; +use std::ops::Mul; +use std::ops::Rem; +use std::ops::Sub; use std::rc::Rc; use std::{cmp::Ordering, fmt::Debug}; @@ -104,6 +108,38 @@ impl<'a> Add<&'a dyn ContextElement> for &'a dyn ContextElement { } } +impl<'a> Sub<&'a dyn ContextElement> for &'a dyn ContextElement { + type Output = Option>; + + fn sub(self, other: &'a dyn ContextElement) -> Self::Output { + self.math_subtract(other) + } +} + +impl<'a> Mul<&'a dyn ContextElement> for &'a dyn ContextElement { + type Output = Option>; + + fn mul(self, other: &'a dyn ContextElement) -> Self::Output { + self.math_multiply(other) + } +} + +impl<'a> Div<&'a dyn ContextElement> for &'a dyn ContextElement { + type Output = Option>; + + fn div(self, other: &'a dyn ContextElement) -> Self::Output { + self.math_divide(other) + } +} + +impl<'a> Rem<&'a dyn ContextElement> for &'a dyn ContextElement { + type Output = Option>; + + fn rem(self, other: &'a dyn ContextElement) -> Self::Output { + self.math_modulus(other) + } +} + pub trait FromContextElement { fn from_context_element(&self) -> &dyn IntoContextElement; } diff --git a/src/renderer/math.rs b/src/renderer/math.rs index 02b305e..0c4456d 100644 --- a/src/renderer/math.rs +++ b/src/renderer/math.rs @@ -1,6 +1,10 @@ use crate::parser::OwnedLiteral; use std::convert::TryInto; use std::ops::Add; +use std::ops::Div; +use std::ops::Mul; +use std::ops::Rem; +use std::ops::Sub; #[derive(Debug)] pub enum MathNumber { @@ -44,6 +48,50 @@ impl Add for MathNumber { } } +impl Sub for MathNumber { + type Output = Option; + + fn sub(self, other: MathNumber) -> Self::Output { + todo!() + } +} + +impl Mul for MathNumber { + type Output = Option; + + fn mul(self, other: MathNumber) -> Self::Output { + todo!() + } +} + +impl Div for MathNumber { + type Output = Option; + + fn div(self, other: MathNumber) -> Self::Output { + todo!() + } +} + +impl Rem for MathNumber { + type Output = Option; + + fn rem(self, other: MathNumber) -> Self::Output { + todo!() + } +} + +impl MathNumber { + fn math_abs(&self) -> Option { + todo!() + } + fn math_floor(&self) -> Option { + todo!() + } + fn math_ceil(&self) -> Option { + todo!() + } +} + /// For math operations that take in integers and return integers /// (add, subtract, multiply) pub fn math_ints(left: L, right: R, operation: F) -> Option