This repository contains various examples demonstrating the usage of RsHtml, a Rust compile-time, type-safe HTML template engine. The goal is to showcase RsHtml's features both as small instructional snippets and as fully working real-world applications.
snippets/– Small, educational examples that produce direct string output.webapp/– Larger project that demonstrate RsHtml in fully working web application.
These examples focus on teaching the fundamental features of RsHtml. Each file demonstrates a specific functionality or usage pattern.
| File | Description |
|---|---|
simple-expression.rs |
Demonstrates how to use Rust variables inside templates (@self.field, @expr()). |
parantheses-expression.rs |
Shows how to use parentheses in expressions (@(expr)). |
if-else.rs |
Shows conditional statements (@if, @else if, @else). |
for.rs |
Demonstrates for loops (@for). |
while.rs |
Demonstrates while loops (@while). |
match.rs |
Demonstrates pattern matching using @match. |
component.rs |
Demonstrates how to use components. |
functions.rs |
Demonstrates how to use built-in functions. |
escaping.rs |
Shows how to escape HTML. |
raw-block.rs |
Shows how to include raw HTML blocks with @raw. |
code-block.rs |
Shows how to use code blocks (@{ ... }). |
comment.rs |
Demonstrates how to use comments. |
Run instructional examples:
cd snippets
cargo run --example simple-expressionReplace simple-expression with the name of any other snippet file to run it.
It demonstrates RsHtml in more complex, real-world scenarios. It is a mini, standalone application that demonstrates how RsHtml integrates into a web environment.
| Project | Description |
|---|---|
web_app/ |
A simple web project that demonstrates the use of RsHtml. |
Run real-world applications:
cd webapp
cargo run- Clone the repository:
git clone https://github.com/rshtml/examples.git
cd examples- Run any instructional snippet:
cd snippets
cargo run --example simple-expression- Or run a full web application:
cd webapp
cargo run