pub struct RuleSet { /* private fields */ }Expand description
Compiled collection of named rules from the config.
Top-level config entries become startable rules, so callers can render
origin, story, name, or any other named entry directly. A top-level
context object is treated specially: its entries become lazy defaults for
bound variables, so {hero} can generate and cache context.hero on first
use within a render.
Implementations§
Source§impl RuleSet
impl RuleSet
Sourcepub fn from_config(config: Value) -> Result<Self, RenderError>
pub fn from_config(config: Value) -> Result<Self, RenderError>
Compiles a parsed configuration root value using the builtin processor registry.
The root value must be a configuration object. Top-level entries become named
rules, except a top-level object named context, whose entries become
lazy defaults available to template references.
Sourcepub fn from_config_with_processors(
config: Value,
custom_processors: ProcessorRegistry,
) -> Result<Self, RenderError>
pub fn from_config_with_processors( config: Value, custom_processors: ProcessorRegistry, ) -> Result<Self, RenderError>
Compiles a parsed configuration root value with additional custom processors.
Custom processors are merged into the builtin registry before templates are compiled, so unknown processor names fail during compilation. A custom processor with the same name as a builtin overrides the builtin.
Sourcepub fn render_rule(&self, rule_name: &str) -> Result<String, RenderError>
pub fn render_rule(&self, rule_name: &str) -> Result<String, RenderError>
Renders a named rule from this ruleset.
Each call starts with a fresh render context. Bindings and lazy context defaults are cached within one render, but not shared with later calls.
Sourcepub fn render_rule_with_context(
&self,
rule_name: &str,
context: RenderContext,
) -> Result<String, RenderError>
pub fn render_rule_with_context( &self, rule_name: &str, context: RenderContext, ) -> Result<String, RenderError>
Renders a named rule with initial render context values.
Initial context values resolve before lazy context defaults and named
rules. They are scoped to this render call and are not stored on the
ruleset.
Sourcepub fn render_rule_inferred(
&self,
rule_name: &str,
) -> Result<String, RenderError>
pub fn render_rule_inferred( &self, rule_name: &str, ) -> Result<String, RenderError>
Renders a named rule as text, inferring structured JSON for object-valued rules.
String-valued and list-valued rules use existing text rendering. Object-valued rules render as formatted JSON using tab indentation.
Sourcepub fn render_rule_inferred_with_context(
&self,
rule_name: &str,
context: RenderContext,
) -> Result<String, RenderError>
pub fn render_rule_inferred_with_context( &self, rule_name: &str, context: RenderContext, ) -> Result<String, RenderError>
Renders a named rule with initial context, inferring structured JSON for object-valued rules.
Sourcepub fn render_rule_structured(
&self,
rule_name: &str,
) -> Result<CopperlaceValue, RenderError>
pub fn render_rule_structured( &self, rule_name: &str, ) -> Result<CopperlaceValue, RenderError>
Renders an object-valued rule as a native structured value.
Each call starts with a fresh render context. Text leaves within the structured object share one render state, so bindings and lazy context defaults are stable within the structured render.
Sourcepub fn render_rule_structured_with_context(
&self,
rule_name: &str,
context: RenderContext,
) -> Result<CopperlaceValue, RenderError>
pub fn render_rule_structured_with_context( &self, rule_name: &str, context: RenderContext, ) -> Result<CopperlaceValue, RenderError>
Renders an object-valued rule as a native structured value with initial context.
Sourcepub fn structured_document(&self) -> &StructuredNode
pub fn structured_document(&self) -> &StructuredNode
Returns the compiled structured document tree.