Converting RValues.

This commit is contained in:
Tom Alexander 2020-05-10 18:10:17 -04:00
parent f386e5c31b
commit 876bced188
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -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<String>,
}
impl From<RValue<'_>> 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<String, OwnedRValue>,
}
#[derive(Clone, Debug)]
pub struct ParametersContext<'a> {
params: HashMap<&'a str, &'a RValue<'a>>,