Skip to main content

smart_format/
lib.rs

1#![deny(unsafe_op_in_unsafe_fn)]
2
3//! Composable, zero-allocation `Display` formatting combinators for Rust.
4//!
5//! `smart-format` provides extension traits that add formatting operations to any type
6//! implementing [`core::fmt::Display`]. Each operation returns a lightweight wrapper struct
7//! that itself implements `Display`, so operations compose without intermediate allocations.
8//!
9//! # Design
10//!
11//! The core idea: a struct that wraps `T: Display` and implements `Display` with a
12//! transformation is a zero-allocation combinator by construction. Chain them, and you
13//! get a streaming pipeline that composes through [`core::fmt::Formatter`] without
14//! intermediate `String` allocations.
15//!
16//! Domain-specific transforms (HTML escaping, URL encoding, XML CDATA) are available
17//! behind feature flags so you only pay for what you use.
18//!
19//! # Features
20//!
21//! - `html` — HTML escape, unescape, and attribute formatting
22//! - `url` — URL percent-encoding (adds `percent-encoding` dependency)
23//! - `xml` — XML CDATA wrapping
24//! - `full` — enables all of the above
25
26pub use smart_string::DisplayExt;
27
28pub mod case;
29pub mod combinator;
30#[cfg(feature = "html")]
31pub mod html;
32pub mod iter;
33pub mod str_buffer;
34#[cfg(feature = "url")]
35pub mod url;
36#[cfg(feature = "xml")]
37pub mod xml;
38
39pub mod prelude {
40    pub use core::fmt;
41
42    pub use smart_string::DisplayExt;
43    pub use smart_string::PascalString;
44
45    pub use crate::case::SmartFormatCase;
46    pub use crate::combinator::SmartFormat;
47    #[cfg(feature = "html")]
48    pub use crate::html::SmartFormatHtml;
49    pub use crate::iter::DisplayIterator;
50    pub use crate::str_buffer::StrBuffer;
51    #[cfg(feature = "url")]
52    pub use crate::url::SmartFormatUrl;
53    #[cfg(feature = "xml")]
54    pub use crate::xml::SmartFormatXml;
55}