Implement addition for OwnedLiterals.

This commit is contained in:
Tom Alexander
2020-06-13 17:50:22 -04:00
parent 8ef3949a65
commit db11677b22
4 changed files with 108 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ use crate::renderer::errors::RenderError;
use crate::renderer::errors::WalkError;
use crate::renderer::DustRenderer;
use std::any::Any;
use std::ops::Add;
use std::rc::Rc;
use std::{cmp::Ordering, fmt::Debug};
@@ -61,6 +62,8 @@ pub trait CompareContextElement: CastToAny {
fn equals(&self, other: &dyn ContextElement) -> bool;
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering>;
fn math_add<'a>(&self, other: &dyn ContextElement) -> Option<IceResult<'a>>;
}
impl<C: 'static + ContextElement> CastToAny for C {
@@ -81,6 +84,14 @@ impl<'a, 'b> PartialOrd<&'b dyn ContextElement> for &'a dyn ContextElement {
}
}
impl<'a> Add<&'a dyn ContextElement> for &'a dyn ContextElement {
type Output = Option<IceResult<'a>>;
fn add(self, other: &'a dyn ContextElement) -> Self::Output {
self.math_add(other)
}
}
pub trait FromContextElement {
fn from_context_element(&self) -> &dyn IntoContextElement;
}
@@ -91,7 +102,7 @@ impl<C: ContextElement> FromContextElement for C {
}
}
pub trait IntoContextElement: Debug + Walkable /* + CloneIntoBoxedContextElement*/ {
pub trait IntoContextElement: Debug + Walkable {
fn into_context_element<'a>(
&'a self,
renderer: &DustRenderer,