Generic implementation of CloneIntoBoxedContextElement.

This commit is contained in:
Tom Alexander
2020-05-10 21:07:31 -04:00
parent ba79369b5a
commit 256051220d
5 changed files with 11 additions and 31 deletions

View File

@@ -5,7 +5,7 @@ use std::any::Any;
use std::fmt::Debug;
pub trait ContextElement:
Debug + Walkable + Renderable + Loopable + IntoBoxedContextElement + CompareContextElement
Debug + Walkable + Renderable + Loopable + CloneIntoBoxedContextElement + CompareContextElement
{
}
@@ -36,10 +36,16 @@ pub trait CompareContextElement {
fn equals(&self, other: &dyn ContextElement) -> bool;
}
pub trait IntoBoxedContextElement {
pub trait CloneIntoBoxedContextElement {
fn clone_to_box(&self) -> Box<dyn ContextElement>;
}
impl<C: 'static + ContextElement + Clone> CloneIntoBoxedContextElement for C {
fn clone_to_box(&self) -> Box<dyn ContextElement> {
Box::new(self.clone())
}
}
impl<'a, 'b> PartialEq<&'b dyn ContextElement> for &'a dyn ContextElement {
fn eq(&self, other: &&'b dyn ContextElement) -> bool {
self.equals(*other)