Implement the render send of integer literals.
This commit is contained in:
parent
79099a8654
commit
9ee8f41022
@ -151,6 +151,11 @@ impl CompareContextElement for serde_json::Value {
|
|||||||
None => (),
|
None => (),
|
||||||
Some(other_string) => return self.as_str().map_or(false, |s| s == other_string),
|
Some(other_string) => return self.as_str().map_or(false, |s| s == other_string),
|
||||||
}
|
}
|
||||||
|
// Handle numeric literals
|
||||||
|
match other.to_any().downcast_ref::<u64>() {
|
||||||
|
None => (),
|
||||||
|
Some(other_num) => return self.as_u64().map_or(false, |n| n == *other_num),
|
||||||
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ use std::collections::HashMap;
|
|||||||
pub enum OwnedRValue {
|
pub enum OwnedRValue {
|
||||||
RVPath(OwnedPath),
|
RVPath(OwnedPath),
|
||||||
RVString(String),
|
RVString(String),
|
||||||
|
RVPositiveInteger(u64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
@ -39,6 +40,7 @@ impl From<&RValue<'_>> for OwnedRValue {
|
|||||||
RValue::RVPath(path) => OwnedRValue::RVPath(OwnedPath {
|
RValue::RVPath(path) => OwnedRValue::RVPath(OwnedPath {
|
||||||
keys: path.keys.iter().map(|k| k.to_string()).collect(),
|
keys: path.keys.iter().map(|k| k.to_string()).collect(),
|
||||||
}),
|
}),
|
||||||
|
RValue::RVPositiveInteger(num) => OwnedRValue::RVPositiveInteger(*num),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,6 +93,7 @@ impl Walkable for ParametersContext {
|
|||||||
match rval {
|
match rval {
|
||||||
OwnedRValue::RVPath(path) => owned_walk_path(&self.breadcrumbs, &path.keys),
|
OwnedRValue::RVPath(path) => owned_walk_path(&self.breadcrumbs, &path.keys),
|
||||||
OwnedRValue::RVString(text) => Ok(text),
|
OwnedRValue::RVString(text) => Ok(text),
|
||||||
|
OwnedRValue::RVPositiveInteger(num) => Ok(num),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,3 +159,35 @@ impl CompareContextElement for String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ContextElement for u64 {}
|
||||||
|
|
||||||
|
impl Renderable for u64 {
|
||||||
|
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||||
|
Ok(self.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Loopable for u64 {
|
||||||
|
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||||
|
vec![self]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Walkable for u64 {
|
||||||
|
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||||
|
Err(WalkError::CantWalk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CompareContextElement for u64 {
|
||||||
|
fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||||
|
// If its a u64 then compare them directly, otherwise defer
|
||||||
|
// to the other type's implementation of CompareContextElement
|
||||||
|
// since the end user could add any type.
|
||||||
|
match other.to_any().downcast_ref::<Self>() {
|
||||||
|
None => other.equals(self),
|
||||||
|
Some(other_num) => self == other_num,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -235,6 +235,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
Some(rval) => match rval {
|
Some(rval) => match rval {
|
||||||
RValue::RVString(text) => Ok(text),
|
RValue::RVString(text) => Ok(text),
|
||||||
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
|
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
|
||||||
|
RValue::RVPositiveInteger(num) => Ok(num),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let right_side: Result<&dyn ContextElement, WalkError> =
|
let right_side: Result<&dyn ContextElement, WalkError> =
|
||||||
@ -243,6 +244,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
Some(rval) => match rval {
|
Some(rval) => match rval {
|
||||||
RValue::RVString(text) => Ok(text),
|
RValue::RVString(text) => Ok(text),
|
||||||
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
|
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
|
||||||
|
RValue::RVPositiveInteger(num) => Ok(num),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if left_side == right_side {
|
if left_side == right_side {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user