Remove RValue from ParametersContext so I can re-use it for calculated values from math.
This commit is contained in:
parent
e6c17fb603
commit
28a4fea96f
@ -24,7 +24,7 @@ use std::collections::HashMap;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ParametersContext<'a> {
|
pub struct ParametersContext<'a> {
|
||||||
parent: Option<&'a ParametersContext<'a>>,
|
parent: Option<&'a ParametersContext<'a>>,
|
||||||
params: HashMap<&'a str, (&'a RValue<'a>, Option<BreadcrumbTreeElement<'a>>)>,
|
params: HashMap<&'a str, Option<BreadcrumbTreeElement<'a>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ParametersContext<'a> {
|
impl<'a> ParametersContext<'a> {
|
||||||
@ -42,26 +42,25 @@ impl<'a> ParametersContext<'a> {
|
|||||||
// then those are resolved at the time of access rather than
|
// then those are resolved at the time of access rather than
|
||||||
// the time of assignment, so we leave them into their
|
// the time of assignment, so we leave them into their
|
||||||
// original IntoContextElement state.
|
// original IntoContextElement state.
|
||||||
let rendered_params: HashMap<&'a str, (&'a RValue<'a>, Option<BreadcrumbTreeElement<'a>>)> =
|
let rendered_params: HashMap<&'a str, Option<BreadcrumbTreeElement<'a>>> = params
|
||||||
params
|
.iter()
|
||||||
.iter()
|
.map(|kvpair| {
|
||||||
.map(|kvpair| {
|
let k = kvpair.key;
|
||||||
let k = kvpair.key;
|
let v: Option<BreadcrumbTreeElement<'a>> = match &kvpair.value {
|
||||||
let v: Option<BreadcrumbTreeElement<'a>> = match &kvpair.value {
|
RValue::RVLiteral(_owned_literal) => {
|
||||||
RValue::RVLiteral(_owned_literal) => {
|
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
||||||
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
}
|
||||||
}
|
RValue::RVPath(_path) => kvpair
|
||||||
RValue::RVPath(_path) => kvpair
|
.value
|
||||||
.value
|
.into_context_element(renderer, breadcrumbs)
|
||||||
.into_context_element(renderer, breadcrumbs)
|
.map(std::convert::From::from),
|
||||||
.map(std::convert::From::from),
|
RValue::RVTemplate(_template) => {
|
||||||
RValue::RVTemplate(_template) => {
|
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
||||||
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
}
|
||||||
}
|
};
|
||||||
};
|
(k, v)
|
||||||
(k, (&kvpair.value, v))
|
})
|
||||||
})
|
.collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
ParametersContext {
|
ParametersContext {
|
||||||
parent: parent,
|
parent: parent,
|
||||||
@ -90,7 +89,7 @@ impl<'a> IntoContextElement for ParametersContext<'a> {
|
|||||||
|
|
||||||
impl<'a> Walkable for ParametersContext<'a> {
|
impl<'a> Walkable for ParametersContext<'a> {
|
||||||
fn walk(&self, segment: &str) -> Result<&dyn IntoContextElement, WalkError> {
|
fn walk(&self, segment: &str) -> Result<&dyn IntoContextElement, WalkError> {
|
||||||
match self.params.get(segment).map(|(_rvalue, bte)| bte) {
|
match self.params.get(segment) {
|
||||||
Some(Some(bte)) => Ok(bte.borrow()),
|
Some(Some(bte)) => Ok(bte.borrow()),
|
||||||
Some(None) => Err(WalkError::CantWalk),
|
Some(None) => Err(WalkError::CantWalk),
|
||||||
None => self
|
None => self
|
||||||
|
@ -668,7 +668,9 @@ impl<'a> DustRenderer<'a> {
|
|||||||
Some(_) => {
|
Some(_) => {
|
||||||
// TODO: math with body, calculate the value and use it like a select block
|
// TODO: math with body, calculate the value and use it like a select block
|
||||||
// Calculate the value
|
// Calculate the value
|
||||||
|
let calculated_value = self.perform_math_operation(breadcrumbs, ¶m_map);
|
||||||
// Generate a ParametersContext with the result of the math operation as key
|
// Generate a ParametersContext with the result of the math operation as key
|
||||||
|
|
||||||
// calculate are_any_checks_true
|
// calculate are_any_checks_true
|
||||||
// Generate a SelectContext
|
// Generate a SelectContext
|
||||||
// render_maybe_body
|
// render_maybe_body
|
||||||
|
Loading…
x
Reference in New Issue
Block a user