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).
 
#![allow(unused)] fn main() { use twust::tw; let class = tw!("bg-blue-500 text-lg hover:bg-blue-600"); assert_eq!(class, "bg-blue-500 text-lg hover:bg-blue-600"); }
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
#![allow(unused)] fn main() { use twust::tw; let class = tw!("bg-red-500 text-lg"); assert_eq!(class, "bg-red-500 text-lg"); }
Restricting to One Class
#![allow(unused)] fn main() { use twust::tw1; let single_class = tw1!("bg-blue-500"); assert_eq!(single_class, "bg-blue-500"); }
Using Multiple Classes As Array
#![allow(unused)] fn main() { use twust::tws; let class_list = tws!["bg-red-500 text-lg", "p-4 bg-blue-500"]; assert_eq!(class_list, ["bg-red-500", "text-lg", "p-4"]); }
Using Multiple Classes As Array: One class per item
#![allow(unused)] fn main() { use twust::tws1; let class_list = tws1!["bg-red-500", "text-lg", "p-4"]; assert_eq!(class_list, ["bg-red-500", "text-lg", "p-4"]); }
Macros
Twust provides the following macros:
tw! - Type-Checked Tailwind Classes
#![allow(unused)] fn main() { use twust::tw; let class = tw!("hover:bg-green-500 text-white font-bold"); assert_eq!(class, "hover:bg-green-500 text-white font-bold"); }
tws! - Compile-time Checked Array of Classes
#![allow(unused)] fn main() { use twust::tws; let class_list = tws!["border", "rounded-md", "shadow"]; assert_eq!(class_list, ["border", "rounded-md", "shadow"]); }
tw1! - Single Tailwind Class Only
#![allow(unused)] fn main() { use twust::tw1; let single_class = tw1!("flex"); assert_eq!(single_class, "flex"); }
tws1! - Array of Single-Class Items Only
#![allow(unused)] fn main() { use twust::tws1; let class_list = tws1!["text-xl", "border", "m-4"]; assert_eq!(class_list, ["text-xl", "border", "m-4"]); }
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
#![allow(unused)] fn main() { tw!("bg-primary text-secondary hover:bg-secondary"); }
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.