Compiling.

Need to see if I can do a generic implemented of IntoBoxedContextElement for all objects implementing Copy, and I need to implement the compare code to make sure this all works before I start integrating this more.
This commit is contained in:
Tom Alexander 2020-05-10 19:07:41 -04:00
parent 5c79b436a0
commit c96b2257d7
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 18 additions and 20 deletions

View File

@ -1,5 +1,6 @@
extern crate nom; extern crate nom;
use crate::renderer::IntoBoxedContextElement;
use parser::Filter; use parser::Filter;
use renderer::compile_template; use renderer::compile_template;
use renderer::CompiledTemplate; use renderer::CompiledTemplate;
@ -137,3 +138,9 @@ impl Loopable for serde_json::Value {
} }
} }
} }
impl IntoBoxedContextElement for serde_json::Value {
fn clone_to_box(&self) -> Box<dyn ContextElement> {
Box::new(self.clone())
}
}

View File

@ -35,13 +35,7 @@ pub trait CompareContextElement {
} }
pub trait IntoBoxedContextElement { pub trait IntoBoxedContextElement {
fn to_box(self) -> Box<dyn ContextElement>; fn clone_to_box(&self) -> Box<dyn ContextElement>;
}
impl<C: 'static + ContextElement> IntoBoxedContextElement for C {
fn to_box(self) -> Box<dyn ContextElement> {
Box::new(self)
}
} }
// impl PartialEq<dyn ContextElement> for dyn ContextElement { // impl PartialEq<dyn ContextElement> for dyn ContextElement {

View File

@ -8,6 +8,7 @@ mod renderer;
mod walking; mod walking;
pub use context_element::ContextElement; pub use context_element::ContextElement;
pub use context_element::IntoBoxedContextElement;
pub use context_element::Loopable; pub use context_element::Loopable;
pub use context_element::Renderable; pub use context_element::Renderable;
pub use context_element::Walkable; pub use context_element::Walkable;

View File

@ -55,22 +55,12 @@ impl NewParametersContext {
.iter() .iter()
.map(|kvpair| (kvpair.key.to_string(), OwnedRValue::from(&kvpair.value))) .map(|kvpair| (kvpair.key.to_string(), OwnedRValue::from(&kvpair.value)))
.collect(); .collect();
let owned_breadcrumbs: Vec<Box<dyn ContextElement>> =
let x: String = "foo".to_owned(); breadcrumbs.iter().map(|ce| ce.clone_to_box()).collect();
let y: &dyn ContextElement = &x as _;
let z: Box<dyn ContextElement> = y.clone().to_box();
// let owned_y: Box<dyn ContextElement> = Box::new(*y.clone());
// unsafe {
// let ce = &mut *y.clone() as *mut dyn ContextElement;
// Box::from_raw(ce);
// }
// let owned_breadcrumbs: Vec<Box<dyn ContextElement>> =
// breadcrumbs.iter().map(|ce| Box::new(*ce.clone())).collect();
NewParametersContext { NewParametersContext {
params: owned_params, params: owned_params,
breadcrumbs: Vec::new(), breadcrumbs: owned_breadcrumbs,
} }
} }
} }
@ -150,3 +140,9 @@ impl Walkable for String {
Err(WalkError::CantWalk) Err(WalkError::CantWalk)
} }
} }
impl IntoBoxedContextElement for String {
fn clone_to_box(&self) -> Box<dyn ContextElement> {
Box::new(self.clone())
}
}