pub struct Copperlace { /* private fields */ }Expand description
Load-once renderer for repeated renders from one configuration.
Copperlace wraps a compiled RuleSet. Use it when rendering more than
one rule, or rendering the same rule multiple times, so the config is not
parsed and compiled for every render.
Implementations§
Source§impl Copperlace
impl Copperlace
Sourcepub fn from_str(config: &str) -> Result<Self, ConfigError>
pub fn from_str(config: &str) -> Result<Self, ConfigError>
Compiles a configuration string into a reusable renderer.
Returns ConfigError::Parse when the string is not valid configuration, and
ConfigError::Render when the parsed config is not a valid Copperlace
rule set.
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, ConfigError>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, ConfigError>
Loads and compiles a configuration file into a reusable renderer.
Returns ConfigError::Parse when the file cannot be loaded as configuration,
and ConfigError::Render when the parsed config is not a valid
Copperlace rule set.
Sourcepub fn render(&self, rule_name: &str) -> Result<String, RenderError>
pub fn render(&self, rule_name: &str) -> Result<String, RenderError>
Renders a named rule from the compiled config.
Each call starts with a fresh render context. Bindings are consistent within one output but do not carry over to later renders.
Sourcepub fn render_with_context(
&self,
rule_name: &str,
context: RenderContext,
) -> Result<String, RenderError>
pub fn render_with_context( &self, rule_name: &str, context: RenderContext, ) -> Result<String, RenderError>
Renders a named rule from the compiled config with initial context.
Initial context values are scoped to this render call. They resolve
before config-defined context defaults and named rules.
Sourcepub fn render_inferred(&self, rule_name: &str) -> Result<String, RenderError>
pub fn render_inferred(&self, rule_name: &str) -> Result<String, RenderError>
Renders a rule as text, inferring formatted structured JSON for object-valued rules.
Sourcepub fn render_inferred_with_context(
&self,
rule_name: &str,
context: RenderContext,
) -> Result<String, RenderError>
pub fn render_inferred_with_context( &self, rule_name: &str, context: RenderContext, ) -> Result<String, RenderError>
Renders a rule with initial context, inferring formatted structured JSON for object-valued rules.
Sourcepub fn render_structured(
&self,
rule_name: &str,
) -> Result<CopperlaceValue, RenderError>
pub fn render_structured( &self, rule_name: &str, ) -> Result<CopperlaceValue, RenderError>
Renders an object-valued rule from the compiled config as a structured value.
Sourcepub fn render_structured_with_context(
&self,
rule_name: &str,
context: RenderContext,
) -> Result<CopperlaceValue, RenderError>
pub fn render_structured_with_context( &self, rule_name: &str, context: RenderContext, ) -> Result<CopperlaceValue, RenderError>
Renders an object-valued rule from the compiled config as a structured value with initial context.