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)]
|
||||
pub struct 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> {
|
||||
@ -42,26 +42,25 @@ impl<'a> ParametersContext<'a> {
|
||||
// then those are resolved at the time of access rather than
|
||||
// the time of assignment, so we leave them into their
|
||||
// original IntoContextElement state.
|
||||
let rendered_params: HashMap<&'a str, (&'a RValue<'a>, Option<BreadcrumbTreeElement<'a>>)> =
|
||||
params
|
||||
.iter()
|
||||
.map(|kvpair| {
|
||||
let k = kvpair.key;
|
||||
let v: Option<BreadcrumbTreeElement<'a>> = match &kvpair.value {
|
||||
RValue::RVLiteral(_owned_literal) => {
|
||||
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
||||
}
|
||||
RValue::RVPath(_path) => kvpair
|
||||
.value
|
||||
.into_context_element(renderer, breadcrumbs)
|
||||
.map(std::convert::From::from),
|
||||
RValue::RVTemplate(_template) => {
|
||||
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
||||
}
|
||||
};
|
||||
(k, (&kvpair.value, v))
|
||||
})
|
||||
.collect();
|
||||
let rendered_params: HashMap<&'a str, Option<BreadcrumbTreeElement<'a>>> = params
|
||||
.iter()
|
||||
.map(|kvpair| {
|
||||
let k = kvpair.key;
|
||||
let v: Option<BreadcrumbTreeElement<'a>> = match &kvpair.value {
|
||||
RValue::RVLiteral(_owned_literal) => {
|
||||
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
||||
}
|
||||
RValue::RVPath(_path) => kvpair
|
||||
.value
|
||||
.into_context_element(renderer, breadcrumbs)
|
||||
.map(std::convert::From::from),
|
||||
RValue::RVTemplate(_template) => {
|
||||
Some(BreadcrumbTreeElement::from_borrowed(&kvpair.value))
|
||||
}
|
||||
};
|
||||
(k, v)
|
||||
})
|
||||
.collect();
|
||||
|
||||
ParametersContext {
|
||||
parent: parent,
|
||||
@ -90,7 +89,7 @@ impl<'a> IntoContextElement for ParametersContext<'a> {
|
||||
|
||||
impl<'a> Walkable for ParametersContext<'a> {
|
||||
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(None) => Err(WalkError::CantWalk),
|
||||
None => self
|
||||
|
@ -668,7 +668,9 @@ impl<'a> DustRenderer<'a> {
|
||||
Some(_) => {
|
||||
// TODO: math with body, calculate the value and use it like a select block
|
||||
// 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
|
||||
|
||||
// calculate are_any_checks_true
|
||||
// Generate a SelectContext
|
||||
// render_maybe_body
|
||||
|
Loading…
Reference in New Issue
Block a user