summaryrefslogtreecommitdiff
path: root/src/template.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-28 16:41:11 +0100
committertroido <troido@protonmail.com>2020-02-28 16:41:11 +0100
commitc846e929a88837094d7a5383a306df1fec56c333 (patch)
tree48ab058d58c090ff00199af6b3eef7d64c7c2c95 /src/template.rs
parentb80036ef629e0803f3a70059a8fa12d1a2ae3b2d (diff)
more specific types!
Diffstat (limited to 'src/template.rs')
-rw-r--r--src/template.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/template.rs b/src/template.rs
index 805a8a3..5539f94 100644
--- a/src/template.rs
+++ b/src/template.rs
@@ -8,9 +8,12 @@ use crate::{
aerr
};
+#[derive(Debug, PartialEq, Eq, Clone, Hash)]
+pub struct EntityType(pub String);
+
#[derive(Debug, Clone, PartialEq)]
pub struct Template {
- pub name: String,
+ pub name: EntityType,
pub args: Vec<Parameter>,
pub kwargs: HashMap<String, Parameter>,
pub save: bool
@@ -21,7 +24,7 @@ impl Template {
pub fn new(name: &str, kwargs: HashMap<String, Parameter>) -> Self {
Self {
- name: name.to_string(),
+ name: EntityType(name.to_string()),
args: Vec::new(),
kwargs,
save: true
@@ -41,7 +44,7 @@ impl Template {
if val.is_string(){
return Ok(Self::empty(val.as_str().ok_or(aerr!("json string is not a string?"))?));
}
- let name = val.get("type").ok_or(aerr!("template doesn't have 'type'"))?.as_str().ok_or(aerr!("template type not a string"))?.to_string();
+ let name = EntityType(val.get("type").ok_or(aerr!("template doesn't have 'type'"))?.as_str().ok_or(aerr!("template type not a string"))?.to_string());
let mut args = Vec::new();
for arg in val.get("args").unwrap_or(&json!([])).as_array().ok_or(aerr!("template args not an array"))? {
args.push(Parameter::guess_from_json(arg).ok_or(aerr!("template arg not a parameter"))?);
@@ -55,12 +58,12 @@ impl Template {
pub fn to_json(&self) -> Value {
if self.args.is_empty() && self.kwargs.is_empty() {
- return json!(self.name);
+ return json!(self.name.0);
}
let jsonargs: Vec<Value> = self.args.iter().map(|a| a.to_json()).collect();
let jsonkwargs: HashMap<&String, Value> = self.kwargs.iter().map(|(k, a)| (k, a.to_json())).collect();
json!({
- "type": self.name,
+ "type": self.name.0,
"args": jsonargs,
"kwargs": jsonkwargs
})