forge-rsx
forge-rsx is a Rust macro library for declarative, JSX-like HTML generation. It allows you to write HTML structures with embedded logic, attributes, nested tags, loops, and more, directly in Rust code with a concise syntax.
Features
- Declarative HTML macro:
rsx!macro - Supports nested tags, attributes, loops, and embedded expressions
- Indentation-aware formatting
- String literal and identifier attributes
- Flexible syntax for defining complex HTML structures
Usage
Run the following Cargo command in your project directory:
cargo add forge-rsx
Or add forge-rsx as a dependency in your Cargo.toml:
[]
= "MAJOR.MINOR.PATCH" # Replace with the latest version
In your Rust code, import the macro:
use rsx;
Macro Variants
lined: produces HTML without indentation or line breaks (single-line output)btfy0: uses 0 spaces (no indentation, minified output)btfy2: Indentation with 2 spaces per level.btfy4: Indentation with 4 spaces per level.
Examples:
rsx!;
rsx!;
rsx!;
Examples
Basic Tag with Content
let greeting = rsx!;
println!;
Nested Tags
let nested_html = rsx!;
println!;
Attributes
let button_html = rsx!;
println!;
Loop Example
let users = vec!;
let list_html = rsx!;
println!;
Full Complex Example
use ;
License
MIT License
Notes
- The macro supports attributes with string literals and identifiers.
- Nested tags are handled with recursive macro calls.
- Looping constructs generate repeated content.
- Content inside braces
{}can contain any Rust expression that implementsDisplay.