Converting RValues.
This commit is contained in:
parent
f386e5c31b
commit
876bced188
@ -9,6 +9,41 @@ use crate::renderer::WalkError;
|
|||||||
use crate::renderer::Walkable;
|
use crate::renderer::Walkable;
|
||||||
use std::collections::HashMap;
|
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)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ParametersContext<'a> {
|
pub struct ParametersContext<'a> {
|
||||||
params: HashMap<&'a str, &'a RValue<'a>>,
|
params: HashMap<&'a str, &'a RValue<'a>>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user