fn evaluate_sub_variables<'a>(key: &str, call_stack: &CallStack<'a>) -> Result<String> {
    let sub_vars_to_calc = pull_out_square_bracket(key);
    let mut new_key = key.to_string();

    for sub_var in &sub_vars_to_calc {
        // Translate from variable name to variable value
        match process_path(sub_var.as_ref(), call_stack) {
            Err(e) => {
                bail!(format!("Variable {} can not be evaluated because: {}", key, e));
            }
            Ok(post_var) => {
                let post_var_as_str = match *post_var {
                    Value::String(ref s) => s.to_string(),
                    Value::Number(ref n) => n.to_string(),
                    _ => bail!(
                        "Only variables evaluating to String or Number can be used as \
                         index (`{}` of `{}`)",
                        sub_var,
                        key,
                    ),
                };

                // Rebuild the original key String replacing variable name with value
                let nk = new_key.clone();
                let divider = "[".to_string() + sub_var + "]";
                let mut the_parts = nk.splitn(2, divider.as_str());

                new_key = the_parts.next().unwrap().to_string()
                    + "."
                    + post_var_as_str.as_ref()
                    + the_parts.next().unwrap_or("");
            }
        }
    }

    Ok(new_key
        .replace("['", ".")
        .replace("[\"", ".")
        .replace("[", ".")
        .replace("']", "")
        .replace("\"]", "")
        .replace("]", ""))
}
/// This will convert a Tera variable to a json pointer if it is possible by replacing
/// the index with their evaluated stringified value
This will convert a Tera variable to a json pointer if it is possible by replacing
the index with their evaluated stringified value
This will convert a Tera variable to a json pointer if it is possible by replacing the index with their evaluated stringified value
fn evaluate_sub_variables<'a>(key: &str, call_stack: &CallStack<'a>) -> Result<String> {
    let sub_vars_to_calc = pull_out_square_bracket(key);
    let mut new_key = key.to_string();
    for sub_var in &sub_vars_to_calc {
        // Translate from variable name to variable value
        match process_path(sub_var.as_ref(), call_stack) {
            Err(e) => {
                bail!(format!("Variable {} can not be evaluated because: {}", key, e));
            }
            Ok(post_var) => {
                let post_var_as_str = match *post_var {
                    Value::String(ref s) => s.to_string(),
                    Value::Number(ref n) => n.to_string(),
                    _ => bail!(
                        "Only variables evaluating to String or Number can be used as \
                         index (`{}` of `{}`)",
                        sub_var,
                        key,
                    ),
                };
                // Rebuild the original key String replacing variable name with value
                let nk = new_key.clone();
                let divider = "[".to_string() + sub_var + "]";
                let mut the_parts = nk.splitn(2, divider.as_str());
                new_key = the_parts.next().unwrap().to_string()
                    + "."
                    + post_var_as_str.as_ref()
                    + the_parts.next().unwrap_or("");
            }
        }
    }
    Ok(new_key
        .replace("['", ".")
        .replace("[\"", ".")
        .replace("[", ".")
        .replace("']", "")
        .replace("\"]", "")
        .replace("]", ""))
}
fn evaluate_sub_variables < ' a > ( key : & str , call_stack : & CallStack < ' a > ) -> Result < String > { let sub_vars_to_calc = pull_out_square_bracket ( key ) ; let mut new_key = key . to_string ( ) ; for sub_var in & sub_vars_to_calc { // Translate from variable name to variable value match process_path ( sub_var . as_ref ( ) , call_stack ) { Err ( e ) => { bail ! ( format ( " " key e ) ) ; } Ok ( post_var ) => { let post_var_as_str = match * post_var { Value :: String ( ref s ) => s . to_string ( ) , Value :: Number ( ref n ) => n . to_string ( ) , _ => bail ! ( " \
 " sub_var key ) , } ; // Rebuild the original key String replacing variable name with value let nk = new_key . clone ( ) ; let divider = " " . to_string ( ) + sub_var + " " ; let mut the_parts = nk . splitn ( 2 , divider . as_str ( ) ) ; new_key = the_parts . next ( ) . unwrap ( ) . to_string ( ) + " " + post_var_as_str . as_ref ( ) + the_parts . next ( ) . unwrap_or ( " " ) ; } } } Ok ( new_key . replace ( " " , " " ) . replace ( " \" " , " " ) . replace ( " " , " " ) . replace ( " " , " " ) . replace ( " \" " , " " ) . replace ( " " , " " ) ) }
This will convert a Tera variable to a json pointer if it is possible by replacing
the index with their evaluated stringified value
This will convert a Tera variable to a json pointer if it is possible by replacing the index with their evaluated stringified value
key
&str
call_stack
&CallStack<'a>
key
&str
call_stack
&CallStack<'a>