summaryrefslogtreecommitdiff
path: root/src/componentparameter.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-06 10:37:53 +0200
committertroido <troido@protonmail.com>2020-04-06 10:37:53 +0200
commite8d3e3c4f69fc5bab2b32b16b7c8c2c4a8a89a4b (patch)
tree67986bb0c0af1abe61dc9846d1a6c8c9b8e2c4b0 /src/componentparameter.rs
parentff457701ff56072914acb8a7160cd02c2a07095a (diff)
made parseerrors their own thing
Diffstat (limited to 'src/componentparameter.rs')
-rw-r--r--src/componentparameter.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/componentparameter.rs b/src/componentparameter.rs
index 28e77ce..73c7b30 100644
--- a/src/componentparameter.rs
+++ b/src/componentparameter.rs
@@ -6,7 +6,9 @@ use crate::{
parameter::{Parameter, ParameterType},
Template,
Result,
- aerr
+ aerr,
+ PResult,
+ perr
};
const MAX_NESTING: usize = 5;
@@ -60,21 +62,21 @@ impl ComponentParameter {
}
}
- pub fn from_json(value: &Value) -> Result<Self> {
- let paramvalue = value.get(1).ok_or(aerr!("index 1 not in component parameter"))?;
- let typename = value.get(0).ok_or(aerr!("index 0 not in component parameter"))?.as_str().ok_or(aerr!("compparam type not a string"))?;
+ pub fn from_json(value: &Value) -> PResult<Self> {
+ let paramvalue = value.get(1).ok_or(perr!("index 1 not in component parameter"))?;
+ let typename = value.get(0).ok_or(perr!("index 0 not in component parameter"))?.as_str().ok_or(perr!("compparam type not a string"))?;
if let Some(paramtype) = ParameterType::from_str(typename) {
Ok(Self::Constant(Parameter::from_typed_json(paramtype, paramvalue).ok_or_else(||
- aerr!("failed to parse parameter constant: {:?} {:?}", paramtype, paramvalue)
+ perr!("failed to parse parameter constant: {:?} {:?}", paramtype, paramvalue)
)?))
} else {
match typename {
"A" | "arg" => {
- let argname = paramvalue.as_str().ok_or(aerr!("argument parameter not a string"))?.to_string();
+ let argname = paramvalue.as_str().ok_or(perr!("argument parameter not a string"))?.to_string();
Ok(Self::Argument(argname))
},
"random" => {
- let optionvalues = paramvalue.as_array().ok_or(aerr!("random argument not an array"))?;
+ let optionvalues = paramvalue.as_array().ok_or(perr!("random argument not an array"))?;
let mut options = Vec::new();
for option in optionvalues {
options.push(Self::from_json(option)?)
@@ -82,7 +84,7 @@ impl ComponentParameter {
Ok(Self::Random(options))
},
"concat" => {
- let values = paramvalue.as_array().ok_or(aerr!("concat argument not an array"))?;
+ let values = paramvalue.as_array().ok_or(perr!("concat argument not an array"))?;
let mut options = Vec::new();
for option in values {
options.push(Self::from_json(option)?)
@@ -91,7 +93,7 @@ impl ComponentParameter {
},
"self" => Ok(Self::TemplateSelf),
"name" => Ok(Self::TemplateName),
- _ => Err(aerr!("unknown compparam type '{}'", typename))
+ _ => Err(perr!("unknown compparam type '{}'", typename))
}
}
}