| Crates.io | classnames-const-rs |
| lib.rs | classnames-const-rs |
| version | 0.1.0 |
| created_at | 2025-05-30 08:46:07.470491+00 |
| updated_at | 2025-05-30 08:46:07.470491+00 |
| description | A Rust implementation of the classnames utility for conditionally joining class names at compile time. |
| homepage | |
| repository | https://github.com/flattoride/classnames-rs/tree/main/crates/classnames-const-rs |
| max_upload_size | |
| id | 1694823 |
| size | 16,841 |
A Rust macro library for compile-time CSS class name concatenation and processing.
Add this to your Cargo.toml:
[dependencies]
classnames-const-rs = "0.1.0"
use classnames_const_rs::*;
const BUTTON_CLASS: &str = classnames_concat!("btn", "btn-primary");
assert_eq!(BUTTON_CLASS, "btn btn-primary");
The macro automatically handles extra whitespace:
use classnames_const_rs::*;
const MESSY_CLASSES: &str = classnames_concat!(" header ", " main ", "footer ");
assert_eq!(MESSY_CLASSES, "header main footer");
Empty strings are handled gracefully:
use classnames_const_rs::*;
const SPARSE_CLASS: &str = classnames_concat!("", "active", "", "highlight");
assert_eq!(SPARSE_CLASS, "active highlight");
use classnames_const_rs::*;
const BASE_CLASSES: &str = "container mx-auto";
const RESPONSIVE_CLASSES: &str = "md:w-1/2 lg:w-1/3";
const STATE_CLASSES: &str = "hover:bg-blue-500 focus:outline-none";
const COMPONENT_CLASSES: &str = classnames_concat!(
BASE_CLASSES,
RESPONSIVE_CLASSES,
STATE_CLASSES,
"p-4 rounded-lg"
);
// Result: "container mx-auto md:w-1/2 lg:w-1/3 hover:bg-blue-500 focus:outline-none p-4 rounded-lg"
classnames_concat!Concatenates multiple class name strings with automatic whitespace handling.
Syntax:
classnames_concat!(class1, class2, ..., classN)
Features:
trim_format!Internal macro for whitespace normalization. Generally not needed for direct use.
This library is perfect for:
Since all processing happens at compile time, there is zero runtime overhead. The resulting strings are embedded directly into your binary as static string literals.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
constcat crate for compile-time string concatenationclassnames library