cco 0.2.0

cascading configuration
Documentation
use super::{Expr, ExprEvaluator};
use crate::err::*;
use crate::eval::*;
use crate::value::*;

#[derive(Debug, Clone)]
pub struct ConcatStringExpr {
    pub parts: Vec<Index>,
}

impl Expr for ConcatStringExpr {
    fn resolve(
        &self,
        index: Index,
        evaluation: &mut dyn ExprEvaluator,
    ) -> Result<ValueOrReference, ErrorKind> {
        evaluation.ensure_resolved(self.parts.to_vec())?;

        let mut text = String::new();
        for &item in &self.parts {
            let value = evaluation.get_value(item)?;
            let value = &value.to_string().ok_or_else(|| ErrorKind::TypeNotAllowed {
                item: index,
                expr: item,
                actual: value.kind(),
                expected: ValueKind::String,
            })?;
            text.push_str(value);
        }
        Ok(Value::String(text).into())
    }
}