| Crates.io | momenta-macros |
| lib.rs | momenta-macros |
| version | 0.2.1 |
| created_at | 2025-06-06 19:23:12.082332+00 |
| updated_at | 2025-07-20 05:00:36.746754+00 |
| description | Procedural macros for momenta, providing JSX-like syntax for Rust |
| homepage | |
| repository | https://github.com/elcharitas/momenta |
| max_upload_size | |
| id | 1703361 |
| size | 45,672 |
A lightweight and intuitive JSX-like syntax implementation for Rust, enabling HTML-like templating with the full power of Rust's type system.
<div />)<></>){expr})Add this to your Cargo.toml:
[dependencies]
momenta = "0.2"
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.
Momenta 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, Momenta enables you to write expressive and type-safe code while still maintaining the simplicity and readability of HTML.
use momenta::prelude::*;
// 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>
{when!(show => <p>This is shown.</p>) else <p>This is hidden.</p>}
</div>
);
// List rendering
let items = &["Item 1", "Item 2", "Item 3"];
let list = rsx!(
<ul>
{items.iter().map(|item| 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();
momenta: Main library cratemomenta-macros: Procedural macros implementationThis project is currently in active development. While basic JSX syntax is supported, many advanced features are still in progress. Contributions are welcome!
MIT License