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§
Required Methods§
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.