pub trait DecoratorPlugin: Send + Sync {
// Provided methods
fn pre_eval(
&self,
_eval: &dyn Evaluator,
_node: &Node,
_scope: &Arc<Scope>,
_args: &[CallArg],
_range: TokenRange,
) -> Result<PreEvalOutcome, RuntimeError> { ... }
fn wrap(
&self,
_eval: &dyn Evaluator,
value: Value,
_scope: &Arc<Scope>,
_args: &[EvaluatedArg],
_range: TokenRange,
) -> Result<Value, RuntimeError> { ... }
fn wrap_with_ast(
&self,
_eval: &dyn Evaluator,
_node: &Node,
_value: &Value,
_scope: &Arc<Scope>,
_ast_args: &[CallArg],
_range: TokenRange,
) -> Result<Option<Value>, RuntimeError> { ... }
fn schema_field_meta(
&self,
_eval: &dyn Evaluator,
_field: &mut SchemaField,
_scope: &Arc<Scope>,
_args: &[EvaluatedArg],
_range: TokenRange,
) -> Result<(), RuntimeError> { ... }
}Expand description
Hosts extend Relon’s @name(...) syntax by implementing this trait and
registering an instance under the decorator’s full dotted path name (e.g.
"import", "ensure.int", "my_org.audit").
Three independent hooks are exposed:
pre_evalruns before the decorated node is evaluated. Use it to inject locals into scope (#import) or take over the value entirely (#schema).wrapruns after the node is evaluated. Use it to validate or transform the value (@ensure.int,@currency("USD")).schema_field_metaruns while extracting fields from a#schema-annotated dict. Use it to attach per-field metadata such as defaults or custom error messages (#expect,#default).
All hooks default to no-op / identity, so plugins only override what they actually need.
Provided Methods§
fn pre_eval( &self, _eval: &dyn Evaluator, _node: &Node, _scope: &Arc<Scope>, _args: &[CallArg], _range: TokenRange, ) -> Result<PreEvalOutcome, RuntimeError>
fn wrap( &self, _eval: &dyn Evaluator, value: Value, _scope: &Arc<Scope>, _args: &[EvaluatedArg], _range: TokenRange, ) -> Result<Value, RuntimeError>
Sourcefn wrap_with_ast(
&self,
_eval: &dyn Evaluator,
_node: &Node,
_value: &Value,
_scope: &Arc<Scope>,
_ast_args: &[CallArg],
_range: TokenRange,
) -> Result<Option<Value>, RuntimeError>
fn wrap_with_ast( &self, _eval: &dyn Evaluator, _node: &Node, _value: &Value, _scope: &Arc<Scope>, _ast_args: &[CallArg], _range: TokenRange, ) -> Result<Option<Value>, RuntimeError>
AST-level wrap hook. Called before Self::wrap: receives the
decorator’s raw CallArg AST nodes (un-evaluated) along with the
host Node so plugins that need to inspect type expressions,
paths, or sibling decorators / type hints can do so without losing
them to evaluation.
Returns Ok(None) to fall through to the standard wrap path.
Returning Ok(Some(val)) short-circuits: wrap is not called and
val becomes the decorator’s output. @brand(Type) uses this to
extract the type name from the un-evaluated AST so a bareword like
Weather doesn’t get resolved to a Value::Schema first.
fn schema_field_meta( &self, _eval: &dyn Evaluator, _field: &mut SchemaField, _scope: &Arc<Scope>, _args: &[EvaluatedArg], _range: TokenRange, ) -> Result<(), RuntimeError>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".