Skip to main content

Template

Struct Template 

Source
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

Source

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.

Source

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.

Source

pub fn eval_into<T: DeserializeOwned>(&self, ctx: &TaskContext<'_>) -> Result<T>

As Self::eval, deserialized into T.

Routes through serde_json::ValueTaskContext::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.

Source

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.

Source

pub fn as_json(&self) -> &Value

The authored JSON, unchanged. For handlers that need to report or re-serialize their own config.

Source

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.

Trait Implementations§

Source§

impl Clone for Template

Source§

fn clone(&self) -> Template

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Template

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Template

Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.