twust
Twust is a powerful static checker in Rust for TailwindCSS class names at compile-time. It ensures correctness by validating class names before runtime, preventing errors and improving developer experience.
twust
Features
- Compile-time validation of Tailwind CSS class names. Prevents typos and invalid Tailwind class names.
- No runtime overhead – errors are caught at compile time.
- Supports single and multiple class formats.
- Supports DaisyU under a feature flag.
- Configurable: Supports overriding, extending, custom classes, custom modifiers, Plugins and many more.
- Flexible macro-based API.
- Returns class names as a string or an array for easy use in UI frameworks.
- Works seamlessly in Rust UI frameworks like Leptos, Dioxus, Yew, and Sycamore.
- Lightweight and blazing fast!
Installation
[]
= "1.0.7"
Enable optional features (e.g., daisyui support):
[]
= { = "1.0.7", = ["daisyui"] }
Usage
tw! - Compile-time Type-Checked Tailwind Classes
use tw;
let class = tw!;
assert_eq!;
// You can also separate classnames by space, these will be merged
let classes_list = tw!;
assert_eq!
// You can override/extend color/background color in tailwind.config.json
tw!;
tw!;
tw!;
tw!;
tw!;
tw!;
tw!;
tw!;
// Even scroll margin can also be configured, here we add, sm and md under the Spacing/scrollMargin field in the config file
tw!;
tw!;
tw!;
tw!;
tws! - Compile-time Checked Array of Classes
use tws;
let class_list = tws!;
assert_eq!;
tw1! - Single Tailwind Class Only
use tw1;
let class = tw1!;
assert_eq!;
tws1! - Array of Single-Class Items Only
use tws1;
let class_list = tws1!;
assert_eq!;
tailwind.config.json Overview
Basic Structure:
Statement of Problem
TailwindCSS offers developers a flexible utility-first approach to styling web applications. However, its flexibility can also lead to potential pitfalls:
- Runtime Errors: Invalid TailwindCSS class names can cause unexpected styling issues that are only caught during runtime.
- Developer Experience: Manually validating class names can be tedious and error-prone.
- Plugin Compatibility: Some TailwindCSS utilities extend their functionality with plugins like DaisyUI, which traditional methods might not support.
- Increased Build Size: Invalid class names that slip into the production code can increase the final CSS bundle size.
Solution
Twust addresses these challenges by offering:
- Compile-time Validation: Ensures that only valid TailwindCSS class names are used, preventing errors in production.
- Seamless Integration: Works within Rust macros for an improved developer experience.
- Plugin Support: Easily integrate popular plugins like DaisyUI with feature flags.
- Optimized Builds: Reduces unnecessary CSS bloat.
How does this compare with Other Rust Libraries?
tailwindcss-to-rust
- Requires complex setup and external dependencies.
- Generates Rust code that must be maintained manually.
- Lacks full support for all Tailwind utilities.
twust
- No setup required – just use the macros.
- Works in real-time at compile-time.
- Self-contained with no external dependencies.
- Supports all standard TailwindCSS class names, including responsive variants.
License
Twust is licensed under MIT/Apache-2.0. See LICENSE for details.
Email: oyelowo.oss@gmail.com
⭐ Show Some Love!
If you find Twust useful, give it a ⭐ on GitHub!