pub struct Template { /* private fields */ }Expand description
A config field whose authored JSON is a JSONLogic expression.
Deserializes from any JSON value and keeps it verbatim; the expression is
compiled once at engine construction (see crate::AsyncFunctionHandler::compile_input)
and evaluated per message on the worker thread’s pooled arena.
Declare this type only on fields the workflow author is told are JSONLogic —
the *_logic convention this crate’s own built-ins use. Do not use it for
freeform config values: LogicCompiler builds its datalogic engine with
templating enabled, so a single-key object whose key happens to match an
operator name ({"cat": ["a", "b"]}) evaluates as that operator rather than
being returned as a literal object. That is existing behaviour for the
built-in *_logic fields, not a Template-specific regression — it is the
reason this type is opt-in per field rather than a blanket JSON wrapper.
Implementations§
Source§impl Template
impl Template
Sourcepub fn compile(&mut self, c: &TemplateCompiler, label: &str) -> Result<()>
pub fn compile(&mut self, c: &TemplateCompiler, label: &str) -> Result<()>
Compile the expression. Called once at engine construction via
crate::AsyncFunctionHandler::compile_input. label is used only in
the error message, matching LogicCompiler’s
"<what> for task <id> in workflow <id>" convention.
§Errors
DataflowError::LogicEvaluation if the expression fails to compile,
with label prefixed onto the message.
Sourcepub fn eval(&self, ctx: &TaskContext<'_>) -> Result<OwnedDataValue>
pub fn eval(&self, ctx: &TaskContext<'_>) -> Result<OwnedDataValue>
Evaluate against the message context, on the worker thread’s pooled bump arena.
§Errors
DataflowError::LogicEvaluation if Self::compile was never called —
naming the field is the caller’s job via label, since this type has no
field name of its own to report — or if evaluation itself fails.
Sourcepub fn eval_into<T: DeserializeOwned>(&self, ctx: &TaskContext<'_>) -> Result<T>
pub fn eval_into<T: DeserializeOwned>(&self, ctx: &TaskContext<'_>) -> Result<T>
As Self::eval, deserialized into T.
Routes through serde_json::Value — TaskContext::eval_json then
serde_json::from_value — so it costs one extra walk and rebuild past
Self::eval. Prefer eval when T is OwnedDataValue or when you
only need to inspect the result, not deserialize it into a caller type.
§Errors
As Self::eval, plus a deserialization error if the evaluated JSON does
not fit T.
Sourcepub fn eval_to_plain_string(&self, ctx: &TaskContext<'_>) -> Result<String>
pub fn eval_to_plain_string(&self, ctx: &TaskContext<'_>) -> Result<String>
As Self::eval, coerced to a plain string via
TaskContext::eval_to_plain_string — a JSON string result yields its
contents, anything else its compact JSON form. Use this when the result
is going into a URL path or a message key, where JSON quoting would be
wrong.
§Errors
As Self::eval.
Sourcepub fn as_json(&self) -> &Value
pub fn as_json(&self) -> &Value
The authored JSON, unchanged. For handlers that need to report or re-serialize their own config.
Sourcepub fn is_compiled(&self) -> bool
pub fn is_compiled(&self) -> bool
Whether Self::compile has run. Mainly for tests and for callers that
want to assert the build pass reached them.