#templating #forge #user-defined #scaffolding #generator #rendering-engine #file-generator

anvil

Anvil is a modular templating system for creating user-defined scaffolding systems

7 releases

0.3.2 Jun 22, 2025
0.3.1 Apr 4, 2025
0.2.2 Jan 26, 2025
0.1.1 Oct 29, 2024

#156 in Template engine

Download history 87/week @ 2025-08-26 192/week @ 2025-09-02 154/week @ 2025-09-09 100/week @ 2025-09-16 109/week @ 2025-09-23 65/week @ 2025-09-30 77/week @ 2025-10-07 97/week @ 2025-10-14 81/week @ 2025-10-21 23/week @ 2025-10-28 16/week @ 2025-11-04 10/week @ 2025-11-11 42/week @ 2025-11-18 17/week @ 2025-11-25 18/week @ 2025-12-02 9/week @ 2025-12-09

88 downloads per month
Used in 8 crates

MIT license

54KB
545 lines

Anvil

Anvil is a modular templating system for creating user-defined scaffolding systems. It provides a composable API for file operations like generating, appending, transforming, and moving files.

Core Concepts

Anvil is built around two primary traits:

  • Anvil - The base trait for template rendering engines
  • Forge - The base trait for file operations using rendered templates

Think of Anvil as the template you render, and Forge as what you do with that rendered content (create a file, append to a file, transform a file, etc.).

Design Philosophy

  • Configuration is code: Your scaffolding logic is defined directly in code, enabling compile-time checking and integration with your application.
  • Compile time errors are better than runtime errors: Detect issues at compile time whenever possible.
  • The library provides the building blocks, not the solutions: Anvil gives you composable components to build your own custom scaffolding systems.

Example Usage

use anvil::{Anvil, Forge, generate::Generate};
use std::io::Write;

// Simple implementation of the Anvil trait
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(())
    }
}

// Using Generate for file creation
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let template = SimpleTemplate {
        content: "Hello, Anvil!".to_string(),
    };
    
    // Create a file generator using our template
    let generator = Generate::new(template);
    
    // Generate the file
    generator.forge("./output.txt")?;
    
    println!("File generated successfully!");
    Ok(())
}

Inspiration and Credits

Dependencies

~170–590KB
~14K SLoC