Add tests and a Sizable trait for ContextElement.

This commit is contained in:
Tom Alexander
2020-06-14 12:54:03 -04:00
parent 76193bf806
commit 1a54e35736
15 changed files with 66 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ use renderer::Loopable;
use renderer::MathNumber;
use renderer::RenderError;
use renderer::Renderable;
use renderer::Sizable;
use renderer::Truthiness;
use renderer::WalkError;
use renderer::Walkable;
@@ -313,6 +314,12 @@ impl Loopable for serde_json::Value {
}
}
impl Sizable for serde_json::Value {
fn get_size<'a>(&'a self) -> Option<IceResult<'a>> {
todo!()
}
}
impl Castable for serde_json::Value {
fn cast_to_type<'a>(&'a self, target: &str) -> Option<IceResult<'a>> {
match (self, target) {

View File

@@ -22,6 +22,7 @@ pub trait ContextElement:
+ FromContextElement
+ IntoRcIce
+ Castable
+ Sizable
{
}
@@ -63,6 +64,10 @@ pub trait Castable {
fn cast_to_type<'a>(&'a self, target: &str) -> Option<IceResult<'a>>;
}
pub trait Sizable {
fn get_size<'a>(&'a self) -> Option<IceResult<'a>>;
}
pub trait CastToAny {
fn to_any(&self) -> &dyn Any;
}

View File

@@ -18,6 +18,7 @@ pub use context_element::IceResult;
pub use context_element::IntoContextElement;
pub use context_element::Loopable;
pub use context_element::Renderable;
pub use context_element::Sizable;
pub use context_element::Truthiness;
pub use context_element::Walkable;
pub use errors::CompileError;

View File

@@ -14,6 +14,7 @@ use crate::renderer::DustRenderer;
use crate::renderer::Loopable;
use crate::renderer::RenderError;
use crate::renderer::Renderable;
use crate::renderer::Sizable;
use crate::renderer::Truthiness;
use crate::renderer::WalkError;
use crate::renderer::Walkable;
@@ -189,6 +190,12 @@ impl Walkable for OwnedLiteral {
}
}
impl Sizable for OwnedLiteral {
fn get_size<'a>(&'a self) -> Option<IceResult<'a>> {
todo!()
}
}
impl Castable for OwnedLiteral {
fn cast_to_type<'a>(&'a self, target: &str) -> Option<IceResult<'a>> {
match (self, target) {