Figured out how to get a value using `to_string()`

Figured out how to get a value using `to_string()` but serde_json's `to_string()` is wrapping a string in quotes. I think I want to implement my own trait to support custom logic for rendering values.
This commit is contained in:
Tom Alexander 2020-04-11 19:03:41 -04:00
parent 265afe7eeb
commit af5122ab9f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 7 additions and 1 deletions

View File

@ -46,6 +46,7 @@ impl<'a> DustRenderer<'a> {
pub fn render<C>(&self, name: &str, context: &C) -> Result<String, RenderError>
where
C: Index<&'a str>,
<C as std::ops::Index<&'a str>>::Output: std::string::ToString,
{
let main_template = match self.templates.get(name) {
Some(tmpl) => tmpl,
@ -61,6 +62,7 @@ impl<'a> DustRenderer<'a> {
fn render_template<C>(&self, template: &Template, context: &C) -> Result<String, RenderError>
where
C: Index<&'a str>,
<C as std::ops::Index<&'a str>>::Output: std::string::ToString,
{
let mut output = String::new();
for elem in &template.contents.elements {
@ -77,10 +79,14 @@ impl<'a> DustRenderer<'a> {
fn render_tag<C>(&self, tag: &DustTag, context: &C) -> Result<String, RenderError>
where
C: Index<&'a str>,
<C as std::ops::Index<&'a str>>::Output: std::string::ToString,
{
match tag {
DustTag::DTComment(comment) => (),
DustTag::DTReference(reference) => (),
DustTag::DTReference(reference) => {
let val = context.index("name");
return Ok(val.to_string());
}
_ => (), // TODO: Implement the rest
}
Ok("".to_owned())