#template #operation #state #framework #execution #flexible #templating

quickform

A flexible templating and operation execution framework for Rust

1 unstable release

new 0.1.0 Dec 15, 2024

#387 in Filesystem

Download history 88/week @ 2024-12-09

88 downloads per month

MIT license

57KB
1K SLoC

QuickForm

QuickForm is a flexible templating and operation execution framework for Rust that provides a type-safe, state-aware system for executing async operations and rendering their results using templates.

Features

  • Type-safe State Management: Support for multiple state types with thread-safe access
  • Async Operations: Execute async functions with state-aware parameters
  • Template Rendering: Integrate with template files for output generation
  • In-memory Filesystem: Virtual filesystem for managing templates and generated files
  • Builder Pattern API: Fluent interface for configuration and setup

Installation

Add QuickForm to your Cargo.toml:

[dependencies]
quickform = "0.1.0"

Usage

Here's a basic example:

use quickform::App;

// Define some state
#[derive(Clone)]
struct User {
    name: String,
    age: u32,
}

// Define an async operation
async fn process_user(user: Data<User>) -> String {
    format!("Hello, {}!", user.name)
}

// Create and run the app
let app = App::new()
    .with_templates("templates/")
    .with_state(User {
        name: "Alice".to_string(),
        age: 30,
    })
    .render_operation("greet.txt", process_user);

// Execute operations and write results
app.run("output/").await?;

State Management

QuickForm provides thread-safe state management through the Data<T> wrapper:

let state = Data::new(User { name: "Alice".to_string() });

// Update state
state.update(|user| user.name = "Bob".to_string()).await;

// Get state value
let user = state.clone_inner().await;

Template Rendering

Templates are loaded from disk and rendered using the MiniJinja engine. Templates can access state data and operation results through a context object.

Example template:

Hello, {{ user.name }}!
Your account was created on {{ user.created_at | date }}.

Operations

QuickForm supports two types of operations:

  1. Render Operations: Execute async functions and render their results using templates
  2. State Operations: Execute async functions that modify application state

Operations can accept up to 4 state parameters and return any serializable type.

Documentation

For detailed documentation and examples, see the API documentation.

License

This project is licensed under the MIT License.

Dependencies

~4–11MB
~121K SLoC