Skip to main content

Copperlace

Struct Copperlace 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn render_inferred(&self, rule_name: &str) -> Result<String, RenderError>

Renders a rule as text, inferring formatted structured JSON for object-valued rules.

Source

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.

Source

pub fn render_structured( &self, rule_name: &str, ) -> Result<CopperlaceValue, RenderError>

Renders an object-valued rule from the compiled config as a structured value.

Source

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.

Trait Implementations§

Source§

impl FromStr for Copperlace

Source§

type Err = ConfigError

The associated error which can be returned from parsing.
Source§

fn from_str(config: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. 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> 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