Skip to main content

RuleSet

Struct RuleSet 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn structured_document(&self) -> &StructuredNode

Returns the compiled structured document tree.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more