winged_rust/lib.rs
1//! Fast, type-safe HTML generation for Rust and WebAssembly.
2//!
3//! A port of [Winged-Swift](https://github.com/micheltlutz/Winged-Swift) 2.0.0: the same
4//! composite tree, the same escape-by-default guarantee, the same compact and pretty
5//! render modes — compiled to native code or to `wasm32-unknown-unknown`.
6//!
7//! # Getting started
8//!
9//! ```
10//! use winged_rust::prelude::*;
11//!
12//! let card = article()
13//! .add_class("card p-4")
14//! .child(h1().text("Welcome to WingedRust!").add_class("text-2xl"))
15//! .child(p().text("Ultra-fast HTML generation compiled to WebAssembly."));
16//!
17//! println!("{}", card.render_pretty());
18//! ```
19//!
20//! # Escaping
21//!
22//! Text content and attribute values are escaped **when they enter the tree**, not when it
23//! is rendered, so nothing is escaped twice and nothing is missed. [`Node::Raw`] is the
24//! documented way to inject markup you already trust.
25//!
26//! ```
27//! use winged_rust::prelude::*;
28//! assert_eq!(p().text("<script>").render(), "<p><script></p>");
29//! ```
30//!
31//! # Render modes
32//!
33//! [`Render::render`] produces a single line; [`Render::render_pretty`] indents. Both take
34//! their configuration from a [`RenderOptions`] value rather than global state, so two
35//! threads can render the same tree differently at the same time.
36//!
37//! # Limits
38//!
39//! Rendering has no depth limit: the writer walks an explicit stack instead of recursing.
40//! What deep trees do cost is output size in pretty mode, which is quadratic in depth
41//! because every line carries one indent string per level. See [`Render`] and
42//! `SECURITY.md`.
43//!
44//! # Parity
45//!
46//! The crate is verified against Winged-Swift's own golden fixtures — the same bytes, from
47//! the same page, built through both APIs. Behavioural differences that were introduced on
48//! purpose are listed in `PORTING.md`.
49
50#![cfg_attr(docsrs, feature(doc_cfg))]
51
52pub mod accessibility;
53pub mod core;
54pub mod document;
55pub mod elements;
56pub mod feed;
57pub mod layout;
58#[macro_use]
59pub mod macros;
60pub mod prelude;
61pub mod seo;
62pub mod sitemap;
63#[cfg(all(feature = "ssg", not(target_arch = "wasm32")))]
64#[cfg_attr(docsrs, doc(cfg(feature = "ssg")))]
65pub mod ssg;
66#[cfg(feature = "wasm")]
67#[cfg_attr(docsrs, doc(cfg(feature = "wasm")))]
68pub mod wasm;
69
70pub use crate::core::{Attribute, Element, Node, Render, RenderOptions};
71pub use crate::document::Document;
72pub use crate::layout::Layout;