Wired up the OwnedLiterals to the math functions.

This commit is contained in:
Tom Alexander
2020-06-13 22:52:07 -04:00
parent fdd467298a
commit 431b34dac7
2 changed files with 64 additions and 10 deletions

View File

@@ -375,30 +375,84 @@ impl CompareContextElement for OwnedLiteral {
}
fn math_subtract<'a>(&self, other: &dyn ContextElement) -> Option<IceResult<'a>> {
todo!()
// If its an OwnedLiteral then subtract them directly,
// otherwise defer to the other type's implementation of
// CompareContextElement since the end user could add any
// type.
match other.to_any().downcast_ref::<Self>() {
None => other.math_subtract(self),
Some(other_literal) => match (self, other_literal) {
(OwnedLiteral::LString(_), _) | (_, OwnedLiteral::LString(_)) => None,
(_, _) => (std::convert::Into::<MathNumber>::into(self)
- std::convert::Into::<MathNumber>::into(other_literal))
.map(IceResult::from_owned),
},
}
}
fn math_multiply<'a>(&self, other: &dyn ContextElement) -> Option<IceResult<'a>> {
todo!()
// If its an OwnedLiteral then multiply them directly,
// otherwise defer to the other type's implementation of
// CompareContextElement since the end user could add any
// type.
match other.to_any().downcast_ref::<Self>() {
None => other.math_multiply(self),
Some(other_literal) => match (self, other_literal) {
(OwnedLiteral::LString(_), _) | (_, OwnedLiteral::LString(_)) => None,
(_, _) => (std::convert::Into::<MathNumber>::into(self)
* std::convert::Into::<MathNumber>::into(other_literal))
.map(IceResult::from_owned),
},
}
}
fn math_divide<'a>(&self, other: &dyn ContextElement) -> Option<IceResult<'a>> {
todo!()
// If its an OwnedLiteral then divide them directly, otherwise
// defer to the other type's implementation of
// CompareContextElement since the end user could add any
// type.
match other.to_any().downcast_ref::<Self>() {
None => other.math_divide(self),
Some(other_literal) => match (self, other_literal) {
(OwnedLiteral::LString(_), _) | (_, OwnedLiteral::LString(_)) => None,
(_, _) => (std::convert::Into::<MathNumber>::into(self)
/ std::convert::Into::<MathNumber>::into(other_literal))
.map(IceResult::from_owned),
},
}
}
fn math_modulus<'a>(&self, other: &dyn ContextElement) -> Option<IceResult<'a>> {
todo!()
// If its an OwnedLiteral then modulus them directly,
// otherwise defer to the other type's implementation of
// CompareContextElement since the end user could add any
// type.
match other.to_any().downcast_ref::<Self>() {
None => other.math_modulus(self),
Some(other_literal) => match (self, other_literal) {
(OwnedLiteral::LString(_), _) | (_, OwnedLiteral::LString(_)) => None,
(_, _) => (std::convert::Into::<MathNumber>::into(self)
% std::convert::Into::<MathNumber>::into(other_literal))
.map(IceResult::from_owned),
},
}
}
fn math_abs<'a>(&self) -> Option<IceResult<'a>> {
todo!()
std::convert::Into::<MathNumber>::into(self)
.math_abs()
.map(IceResult::from_owned)
}
fn math_floor<'a>(&self) -> Option<IceResult<'a>> {
todo!()
std::convert::Into::<MathNumber>::into(self)
.math_floor()
.map(IceResult::from_owned)
}
fn math_ceil<'a>(&self) -> Option<IceResult<'a>> {
todo!()
std::convert::Into::<MathNumber>::into(self)
.math_ceil()
.map(IceResult::from_owned)
}
}