summaryrefslogtreecommitdiff
path: root/src/parameter.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-07 15:29:36 +0100
committertroido <troido@protonmail.com>2020-02-07 15:29:36 +0100
commit3e2a991c0e3133428d490399a04822b973c1d99d (patch)
tree47e52c39578add8973f0a9fc6c17403fcc18fa21 /src/parameter.rs
parentbed274c683ffd18a55282247d47780c4f1bf84b5 (diff)
templates can be loaded from json now
Diffstat (limited to 'src/parameter.rs')
-rw-r--r--src/parameter.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/parameter.rs b/src/parameter.rs
index 3ae88cd..4b40c10 100644
--- a/src/parameter.rs
+++ b/src/parameter.rs
@@ -27,9 +27,19 @@ impl Parameter {
}
}
-// pub fn from_json(val: &Value) -> Option<Parameter> {
-// Self::from_typed_json(ParameterType::from_str(val.get(0)?.as_str()?)?, val.get(1)?)
-// }
+ pub fn guess_from_json(val: &Value) -> Option<Parameter> {
+ let typ =
+ if val.is_string() {
+ ParameterType::String
+ } else if val.is_u64() || val.is_i64() {
+ ParameterType::Int
+ } else if val.is_f64() {
+ ParameterType::Float
+ } else {
+ return None
+ };
+ Self::from_typed_json(typ, val.get(1)?)
+ }
pub fn as_str(&self) -> Option<&str> {
if let Self::String(str) = self {