Twust - Static TailwindCSS Validation in Rust
Twust is a compile-time TailwindCSS static checker for Rust. It validates class names before runtime, preventing typos, incorrect class names, and misconfigurations.
Why Twust?
- Compile-time validation: Catch invalid TailwindCSS classes before your Rust app runs.
- Zero runtime overhead: Errors are flagged at compile time.
- Supports Tailwind plugins like DaisyUI (via feature flags).
- Works with Rust UI frameworks (Leptos, Dioxus, Yew, Sycamore).
Installation
Twust is available on crates.io. Add it to your Cargo.toml
:
[dependencies]
twust = "1.0.7"
# Enable optional features like daisyui:
twust = { version = "1.0.7", features = ["daisyui"] }
Usage
Twust provides macros to validate TailwindCSS classes at compile time.
Basic Example
Restricting to One Class
Using Multiple Classes As Array
Using Multiple Classes As Array: One class per item
Macros
Twust provides the following macros:
tw!
- Type-Checked Tailwind Classes
tws!
- Compile-time Checked Array of Classes
tw1!
- Single Tailwind Class Only
tws1!
- Array of Single-Class Items Only
Configuration
Tailwind Configuration
Twust reads custom Tailwind settings from tailwind.config.json
.
Example Configuration
{
"theme": {
"extend": {
"colors": {
"primary": "#ff6347",
"secondary": "#4a90e2"
}
}
},
"corePlugins": {
"preflight": false
},
"variants": {
"backgroundColor": ["responsive", "hover", "focus"]
}
}
Using Custom Classes
FAQ
Why use Twust instead of tailwindcss-to-rust?
Twust is simpler, requires no setup, and validates classes at compile-time instead of generating code.
Can I use this with DaisyUI?
Yes! Enable the feature flag:
twust = { version = "1.0.7", features = ["daisyui"] }
Contributing
Steps
- Fork the repository.
- Clone it locally:
git clone https://github.com/oyelowo/twust.git
- Create a feature branch:
git checkout -b feature-name
- Make changes and commit:
git commit -m "Add new feature"
- Push your branch and open a PR.
License
License
Twust is licensed under MIT/Apache-2.0.
© Oyelowo Oyedayo. See LICENSE
for details.