Crate simple_rsx

Source
Expand description

Simple RSX - A lightweight JSX-like library for Rust

This crate provides a simple way to write HTML-like components in Rust using JSX-style syntax. It’s perfect for building user interfaces or generating HTML content with a familiar, component-based approach.

§Quick Start

use simple_rsx::*;

// Create a simple component
let greeting = rsx!(
    <div class="greeting">
        <h1>Hello, World!</h1>
        <p>Welcome to Simple RSX</p>
    </div>
);

// Convert to HTML string
println!("{}", greeting); // Outputs the HTML

§Features

  • JSX-like syntax with the rsx! macro
  • Component-based architecture
  • Type-safe attributes and children
  • Easy conversion to HTML strings
  • Support for custom components

§Custom Components

use simple_rsx::*;

#[derive(Default)]
struct ButtonProps {
    text: String,
    children: Vec<Node>,
}

#[component]
fn Button(props: ButtonProps) -> Node {
    rsx!(
        <button class="btn">
            {props.text}
            {props.children}
        </button>
    )
}

Macros§

rsx
A procedural macro that provides JSX-like syntax for creating HTML elements in Rust.

Structs§

Element
Represents an HTML element with its tag name, attributes, and children.
HTMLAElementProps
HTMLAudioElementProps
HTMLBodyElementProps
HTMLBrElementProps
HTMLButtonElementProps
HTMLCanvasElementProps
HTMLCircleElementProps
HTMLDefsElementProps
HTMLDivElementProps
HTMLEllipseElementProps
HTMLForeignObjectElementProps
HTMLFormElementProps
HTMLGElementProps
HTMLH1ElementProps
HTMLH2ElementProps
HTMLH3ElementProps
HTMLH4ElementProps
HTMLH5ElementProps
HTMLH6ElementProps
HTMLHeadElementProps
HTMLHrElementProps
HTMLHtmlElementProps
HTMLIframeElementProps
HTMLImgElementProps
HTMLInputElementProps
HTMLLabelElementProps
HTMLLiElementProps
HTMLLineElementProps
HTMLLinearGradientElementProps
HTMLLinkElementProps
HTMLMaskElementProps
HTMLMetaElementProps
HTMLOlElementProps
HTMLOptionElementProps
HTMLPElementProps
HTMLPathElementProps
HTMLPolygonElementProps
HTMLPolylineElementProps
HTMLRadialGradientElementProps
HTMLRectElementProps
HTMLScriptElementProps
HTMLSelectElementProps
HTMLSourceElementProps
HTMLSpanElementProps
HTMLStopElementProps
HTMLStyleElementProps
HTMLSvgElementProps
HTMLTableElementProps
HTMLTbodyElementProps
HTMLTdElementProps
HTMLTextareaElementProps
HTMLTfootElementProps
HTMLThElementProps
HTMLTheadElementProps
HTMLTitleElementProps
HTMLTrElementProps
HTMLUlElementProps
HTMLUseElementProps
HTMLVideoElementProps
a
HTML <a> element - Creates a hyperlink to other web pages or resources
audio
HTML <audio> element - Embeds sound content in the document
body
HTML <body> element - Represents the content of an HTML document
br
HTML <br> element - Produces a line break in text
button
HTML <button> element - Clickable button control
canvas
HTML <canvas> element - Container for graphics rendered with JavaScript
circle
HTML <circle> element - Draws a circle in SVG
defs
HTML <defs> element - Container for reusable SVG elements
div
HTML <div> element - Container element for grouping and styling content
ellipse
HTML <ellipse> element - Draws an ellipse in SVG
foreignObject
HTML element - Includes non-SVG elements inside SVG
form
HTML <form> element - Container for interactive inputs to collect user data
g
HTML <g> element - Groups SVG elements together
h1
HTML

element - First level heading (most important)

h2
HTML

element - Second level heading

h3
HTML

element - Third level heading

h4
HTML

element - Fourth level heading

h5
HTML
element - Fifth level heading
h6
HTML
element - Sixth level heading (least important)
head
HTML <head> element - Contains metadata about the document
hr
HTML <hr> element - Creates a horizontal rule (divider)
html
HTML <html> element - Root element of an HTML document
iframe
HTML <iframe> element - Embeds another document within the current HTML document
img
HTML <img> element - Embeds an image into the document
input
HTML <input> element - Creates interactive controls for forms
label
HTML <label> element - Caption for a form control
li
HTML <li> element - List item within ordered or unordered lists
line
HTML <line> element - Draws a line in SVG
linearGradient
HTML element - Defines a linear gradient for SVG fills
link
HTML <link> element - Specifies relationships between the current document and an external resource
mask
HTML <mask> element - Defines an area where SVG elements are partially or fully hidden
meta
HTML <meta element - Provides metadata about the document
ol
HTML <ol> element - Ordered (numbered) list
option
HTML <option> element - Defines option in a select dropdown
p
HTML <p> element - Represents a paragraph of text
path
HTML <path> element - Defines a path in SVG graphics
polygon
HTML <polygon> element - Draws a closed shape with straight lines in SVG
polyline
HTML <polyline> element - Draws connected straight lines in SVG
radialGradient
HTML element - Defines a radial gradient for SVG fills
rect
HTML <rect> element - Draws a rectangle in SVG
script
HTML <script> element - Embeds executable code or data
select
HTML <select> element - Dropdown selection list
source
HTML <source> element - Defines media resources for video/audio elements
span
HTML <span> element - Inline container for targeting text with styles
stop
HTML <stop> element - Defines color transitions in gradients
style
HTML <style> element - Defines style information for a document
svg
HTML <svg> element - Container for SVG graphics
table
HTML <table> element - Creates a data table with rows and columns
tbody
HTML <tbody> element - Groups body content in a table
td
HTML <td> element - Table data cell
textarea
HTML <textarea> element - Multi-line text input control
tfoot
HTML <tfoot> element - Groups footer content in a table
th
HTML <th> element - Table header cell
thead
HTML <thead> element - Groups header content in a table
title
HTML <title> element - Defines the title of the document
tr
HTML <tr> element - Table row container
ul
HTML <ul> element - Unordered list with bullet points
use
HTML <use> element - Reuses an SVG element defined elsewhere
video
HTML <video> element - Embeds video content in the document

Enums§

Node
Represents a node in the RSX tree.

Traits§

Attribute
A trait for converting values into HTML attribute strings.
Component
A trait for creating reusable components.
OptionAttribute
A trait for handling optional attribute values.

Attribute Macros§

component
A procedural macro that transforms a rust function into a component.