Implement ContextElement for serde_json::Value
This commit is contained in:
parent
0f60baf31c
commit
e5e1703fab
23
src/bin.rs
23
src/bin.rs
@ -2,8 +2,10 @@ extern crate nom;
|
|||||||
|
|
||||||
use renderer::compile_template;
|
use renderer::compile_template;
|
||||||
use renderer::CompiledTemplate;
|
use renderer::CompiledTemplate;
|
||||||
|
use renderer::ContextElement;
|
||||||
use renderer::DustRenderer;
|
use renderer::DustRenderer;
|
||||||
use renderer::Renderable;
|
use renderer::Renderable;
|
||||||
|
use renderer::Walkable;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
@ -67,6 +69,8 @@ fn read_context_from_stdin() -> serde_json::map::Map<String, serde_json::Value>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ContextElement for serde_json::Value {}
|
||||||
|
|
||||||
impl Renderable for serde_json::Value {
|
impl Renderable for serde_json::Value {
|
||||||
fn render(&self) -> String {
|
fn render(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
@ -79,3 +83,22 @@ impl Renderable for serde_json::Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Walkable for serde_json::Value {
|
||||||
|
fn walk(&self, segment: &str) -> &dyn ContextElement {
|
||||||
|
match self {
|
||||||
|
serde_json::Value::Null => panic!("Attempted to walk to {} on a null value", segment),
|
||||||
|
serde_json::Value::Bool(_boolean) => {
|
||||||
|
panic!("Attempted to walk to {} on a boolean value", segment)
|
||||||
|
}
|
||||||
|
serde_json::Value::Number(_num) => {
|
||||||
|
panic!("Attempted to walk to {} on a number value", segment)
|
||||||
|
}
|
||||||
|
serde_json::Value::String(_string) => {
|
||||||
|
panic!("Attempted to walk to {} on a string value", segment)
|
||||||
|
}
|
||||||
|
serde_json::Value::Array(_arr) => todo!("Arrays not supported yet"),
|
||||||
|
serde_json::Value::Object(obj) => obj.get(segment).unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user