diff --git a/src/renderer/parameters_context.rs b/src/renderer/parameters_context.rs index c2aa6d0..289afba 100644 --- a/src/renderer/parameters_context.rs +++ b/src/renderer/parameters_context.rs @@ -9,6 +9,41 @@ use crate::renderer::WalkError; use crate::renderer::Walkable; use std::collections::HashMap; +/// Copy the data from an RValue to an Owned struct +/// +/// In order to get comparisons to work for our `ContextElement` trait +/// objects, we need to be able to use `std::any::Any`. Unfortunately, +/// `Any` requires that the structs do not have a lifetime (so they +/// will have a `'static` lifetime. This means that we cannot have a +/// `<'a>` appended to the struct type, so the struct cannot contain +/// any borrows. Rather than impose the copy cost in the parser, we +/// are imposing the cost of copying the data in the renderer because +/// the parser has no reason to not be able to reference data from the +/// input string. +pub enum OwnedRValue { + RVPath(OwnedPath), + RVString(String), +} + +pub struct OwnedPath { + pub keys: Vec, +} + +impl From> for OwnedRValue { + fn from(original: RValue<'_>) -> Self { + match original { + RValue::RVString(text) => OwnedRValue::RVString(text.to_owned()), + RValue::RVPath(path) => OwnedRValue::RVPath(OwnedPath { + keys: path.keys.iter().map(|k| k.to_string()).collect(), + }), + } + } +} + +pub struct NewParametersContext { + params: HashMap, +} + #[derive(Clone, Debug)] pub struct ParametersContext<'a> { params: HashMap<&'a str, &'a RValue<'a>>,