Simple RSX
A lightweight and intuitive JSX-like syntax implementation for Rust, enabling HTML-like templating with the full power of Rust's type system.
Features
- JSX-like syntax support in Rust
- Self-closing tags (
<div />) - Element attributes
- Nested elements
- String literals as children
- Fragment support (
<></>) - Basic error handling and validation
- Tag matching validation
- Procedural macro implementation
- Basic HTML element rendering
- Expression support in braces (
{expr}) - attribute value concatenation and interpolation
- Conditional attributes
- Conditional rendering
- Looping
- List rendering
- Custom components (partial support through functions)
- Props validation
- State management
- Lifecycle hooks
- Event handling
- Server-side rendering
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Why Simple RSX?
I started this project while attempting to transit my portfolio from Next.js to Rust. I tried using dioxus, yew, and hypertext, but I found them to be too complex and verbose for my needs. I wanted a simple and intuitive way to write HTML-like templates in Rust, while still leveraging the full power of Rust's type system.
Simple RSX aims to provide a straightforward and intuitive way to write HTML-like templates in Rust, while still leveraging the full power of Rust's type system. By using Rust's syntax and features, Simple RSX enables you to write expressive and type-safe code while still maintaining the simplicity and readability of HTML.
Usage
use *;
// Self-closing tag with attributes
let element = rsx!;
// Nested elements with text content
let nested = rsx!;
// element with attributes and children
let element_with_children = rsx!;
// Fragment syntax
let fragment = rsx!;
// Expression support
let count = 42;
let expression = rsx!;
// Conditional rendering
let show = true;
let conditional = rsx!;
// List rendering
let items = vec!;
let list = rsx!;
// Server-side rendering
let nodes = rsx!;
let html = nodes.to_string;
Project Structure
simple-rsx: Main library cratesimple-rsx-macros: Procedural macros implementation
Development Status
This project is currently in active development. While basic JSX syntax is supported, many advanced features are still in progress. Contributions are welcome!
Alternatives
License
MIT License