Trait Anvil

Source
pub trait Anvil {
    type Error: Error + 'static;

    // Required method
    fn anvil(
        &self,
        writer: &mut (impl Write + Sized),
    ) -> Result<(), Self::Error>;
}
Expand description

The core trait for template rendering engines.

Anvil provides the foundational functionality for rendering templates into strings or writing them directly to files. Any type that implements this trait can be used with the file operation types (Generate, Append, etc).

§Type Parameters

  • Error - The error type that the rendering engine can produce.

§Implementation

When implementing this trait, you should provide the rendering logic in the anvil method, which writes the rendered template to the provided writer.

§Examples

use anvil::Anvil;
use std::io::Write;

struct SimpleTemplate {
    content: String,
}

impl Anvil for SimpleTemplate {
    type Error = std::io::Error;

    fn anvil(&self, writer: &mut (impl Write + Sized)) -> Result<(), Self::Error> {
        writer.write_all(self.content.as_bytes())?;
        Ok(())
    }
}

Required Associated Types§

Source

type Error: Error + 'static

The error type that this anvil implementation can produce.

Required Methods§

Source

fn anvil(&self, writer: &mut (impl Write + Sized)) -> Result<(), Self::Error>

Renders the template to the provided writer.

§Parameters
  • writer - A mutable reference to any type that implements std::io::Write. The rendered content will be written to this writer.
§Returns
  • Result<(), Self::Error> - Ok if rendering was successful, Err otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§