feat: rc variable (#246)

* feat: rc variable

* feat: implement variable in engine

* add exports

* fix bindings and improve clone accuracy

* fix tests, fix bindings

* fix fmt

* improve code
This commit is contained in:
stefan-gorules
2024-09-30 18:34:54 +02:00
committed by GitHub
parent 06df117694
commit 91598166ce
55 changed files with 1148 additions and 1399 deletions
+5 -5
View File
@@ -18,17 +18,17 @@ pub fn evaluate_expression(
.context("Failed to convert context")?
.unwrap_or(Value::Null);
let result = zen_expression::evaluate_expression(expression.as_str(), &context)
let result = zen_expression::evaluate_expression(expression.as_str(), context.into())
.map_err(|e| anyhow!(serde_json::to_string(&e).unwrap_or_else(|_| e.to_string())))?;
Ok(PyValue(result).to_object(py))
Ok(PyValue(result.to_value()).to_object(py))
}
#[pyfunction]
pub fn evaluate_unary_expression(expression: String, ctx: &PyDict) -> PyResult<bool> {
let context: Value = depythonize(ctx).context("Failed to convert context")?;
let result = zen_expression::evaluate_unary_expression(expression.as_str(), &context)
let result = zen_expression::evaluate_unary_expression(expression.as_str(), context.into())
.map_err(|e| anyhow!(serde_json::to_string(&e).unwrap_or_else(|_| e.to_string())))?;
Ok(result)
@@ -38,8 +38,8 @@ pub fn evaluate_unary_expression(expression: String, ctx: &PyDict) -> PyResult<b
pub fn render_template(py: Python, template: String, ctx: &PyDict) -> PyResult<PyObject> {
let context: Value = depythonize(ctx).context("Failed to convert context")?;
let result = zen_tmpl::render(template.as_str(), &context)
let result = zen_tmpl::render(template.as_str(), context.into())
.map_err(|e| anyhow!(serde_json::to_string(&e).unwrap_or_else(|_| e.to_string())))?;
Ok(PyValue(result).to_object(py))
Ok(PyValue(result.to_value()).to_object(py))
}