simple-rsx-macros 0.1.2

Procedural macros for simple-rsx, providing JSX-like syntax for Rust
Documentation
simple-rsx-macros-0.1.2 has been yanked.

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})
  • Props validation
  • attribute value concatenation and interpolation
  • Conditional attributes
  • Event handling
  • Conditional rendering
  • Looping
  • List rendering
  • Custom components
  • State management
  • Lifecycle hooks
  • Server-side rendering
  • Server-side rendering with hydration

Installation

Add this to your Cargo.toml:

[dependencies]
simple-rsx = "0.1"

Usage

use simple_rsx::*;

// Self-closing tag with attributes
let element = rsx!(<div class="container" id="app" />);

// Nested elements with text content
let nested = rsx!(
    <div class="container" id="app">
        <p>"Hello, world!"</p>
    </div>
);

// element with attributes and children
let element_with_children = rsx!(
    <div class="container" id="app">
        <p>"Hello, world!"</p>
        <p>"Another paragraph."</p>
    </div>
);

// Fragment syntax
let fragment = rsx!(
    <>
        <h1>"Title"</h1>
        <p>"Content"</p>
    </>
);

// Expression support
let count = 42;
let expression = rsx!(<p>"Count: {count}"</p>);

// Conditional rendering
let show = true;
let conditional = rsx!(
    <div>
        {if show {
            rsx!(<p>"This is shown."</p>)
        } else {
            rsx!(<p>"This is hidden."</p>)
        }}
    </div>
);

// List rendering
let items = vec!["Item 1", "Item 2", "Item 3"];
let list = rsx!(
    <ul>
        {for item in items {
            rsx!(<li>{item}</li>)
        }}
    </ul>
);

// Server-side rendering
let nodes = rsx!(
    <html>
        <head>
            <title>"My Page"</title>
        </head>
        <body>
            <h1>"Welcome to my page!"</h1>
        </body>
    </html>
);
let html = nodes.to_string();

Project Structure

  • simple-rsx: Main library crate
  • simple-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!

License

MIT License