Starting a type casting trait
This commit is contained in:
parent
11096d7ece
commit
9eb70f436c
@ -5,6 +5,7 @@ use parser::Filter;
|
|||||||
use parser::OwnedLiteral;
|
use parser::OwnedLiteral;
|
||||||
use parser::Template;
|
use parser::Template;
|
||||||
use renderer::compile_template;
|
use renderer::compile_template;
|
||||||
|
use renderer::Castable;
|
||||||
use renderer::CompileError;
|
use renderer::CompileError;
|
||||||
use renderer::ContextElement;
|
use renderer::ContextElement;
|
||||||
use renderer::DustRenderer;
|
use renderer::DustRenderer;
|
||||||
@ -312,6 +313,12 @@ impl Loopable for serde_json::Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Castable for serde_json::Value {
|
||||||
|
fn cast_to_type<'a>(&'a self, target: &str) -> Option<IceResult<'a>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl CompareContextElement for serde_json::Value {
|
impl CompareContextElement for serde_json::Value {
|
||||||
fn equals(&self, other: &dyn ContextElement) -> bool {
|
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||||
// Handle other serde_json::Value
|
// Handle other serde_json::Value
|
||||||
|
@ -17,6 +17,7 @@ pub trait ContextElement:
|
|||||||
+ CompareContextElement
|
+ CompareContextElement
|
||||||
+ FromContextElement
|
+ FromContextElement
|
||||||
+ IntoRcIce
|
+ IntoRcIce
|
||||||
|
+ Castable
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +55,10 @@ pub trait Loopable {
|
|||||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement>;
|
fn get_loop_elements(&self) -> Vec<&dyn ContextElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Castable {
|
||||||
|
fn cast_to_type<'a>(&'a self, target: &str) -> Option<IceResult<'a>>;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait CastToAny {
|
pub trait CastToAny {
|
||||||
fn to_any(&self) -> &dyn Any;
|
fn to_any(&self) -> &dyn Any;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ mod renderer;
|
|||||||
mod select_context;
|
mod select_context;
|
||||||
mod walking;
|
mod walking;
|
||||||
|
|
||||||
|
pub use context_element::Castable;
|
||||||
pub use context_element::CompareContextElement;
|
pub use context_element::CompareContextElement;
|
||||||
pub use context_element::ContextElement;
|
pub use context_element::ContextElement;
|
||||||
pub use context_element::IceResult;
|
pub use context_element::IceResult;
|
||||||
|
@ -9,6 +9,7 @@ use crate::renderer::context_element::IceResult;
|
|||||||
use crate::renderer::context_element::IntoContextElement;
|
use crate::renderer::context_element::IntoContextElement;
|
||||||
use crate::renderer::math::MathNumber;
|
use crate::renderer::math::MathNumber;
|
||||||
use crate::renderer::walking::walk_path;
|
use crate::renderer::walking::walk_path;
|
||||||
|
use crate::renderer::Castable;
|
||||||
use crate::renderer::DustRenderer;
|
use crate::renderer::DustRenderer;
|
||||||
use crate::renderer::Loopable;
|
use crate::renderer::Loopable;
|
||||||
use crate::renderer::RenderError;
|
use crate::renderer::RenderError;
|
||||||
@ -167,6 +168,12 @@ impl Walkable for OwnedLiteral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Castable for OwnedLiteral {
|
||||||
|
fn cast_to_type<'a>(&'a self, target: &str) -> Option<IceResult<'a>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl CompareContextElement for OwnedLiteral {
|
impl CompareContextElement for OwnedLiteral {
|
||||||
fn equals(&self, other: &dyn ContextElement) -> bool {
|
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||||
// If its an OwnedLiteral then compare them directly,
|
// If its an OwnedLiteral then compare them directly,
|
||||||
|
@ -964,6 +964,13 @@ impl<'a> DustRenderer<'a> {
|
|||||||
.map(|ice| ice.get_context_element_reference())
|
.map(|ice| ice.get_context_element_reference())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO convert string to number or render NaN
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Doing {:?} {:?} {:?}",
|
||||||
|
left_side, method_rendered, right_side
|
||||||
|
);
|
||||||
|
|
||||||
return match method_rendered.as_str() {
|
return match method_rendered.as_str() {
|
||||||
"add" => match (left_side_ce, right_side_ce) {
|
"add" => match (left_side_ce, right_side_ce) {
|
||||||
(None, _) | (Some(Err(_)), _) | (_, None) | (_, Some(Err(_))) => None,
|
(None, _) | (Some(Err(_)), _) | (_, None) | (_, Some(Err(_))) => None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user