Starting an IntoContextElement trait to allow for delayed evaluation.

This commit is contained in:
Tom Alexander
2020-05-30 16:34:32 -04:00
parent 581f9f7e97
commit 975ab278ef
5 changed files with 53 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ pub trait ContextElement:
+ Loopable
+ CloneIntoBoxedContextElement
+ CompareContextElement
+ FromContextElement
{
}
@@ -86,3 +87,23 @@ impl<'a, 'b> PartialOrd<&'b dyn ContextElement> for &'a dyn ContextElement {
self.partial_compare(*other)
}
}
pub trait FromContextElement {
fn from_context_element(&self) -> &dyn IntoContextElement;
}
impl<C: ContextElement> FromContextElement for C {
fn from_context_element(&self) -> &dyn IntoContextElement {
self
}
}
pub trait IntoContextElement {
fn into_context_element(&self) -> &dyn ContextElement;
}
impl<C: ContextElement> IntoContextElement for C {
fn into_context_element(&self) -> &dyn ContextElement {
self
}
}