| Crates.io | derive_screaming_snake_case |
| lib.rs | derive_screaming_snake_case |
| version | 1.0.0 |
| created_at | 2025-05-15 04:59:09.662122+00 |
| updated_at | 2025-05-15 08:27:27.648779+00 |
| description | A lightweight Rust proc-macro crate that implements the Display trait for enums with unit variants by converting each variant's name into SCREAMING_SNAKE_CASE. |
| homepage | https://github.com/abhinandh-s/derive_screaming_snake_case |
| repository | https://github.com/abhinandh-s/derive_screaming_snake_case |
| max_upload_size | |
| id | 1674398 |
| size | 10,510 |
A lightweight Rust proc-macro crate that implements the Display trait for enums with unit variants by converting each variant's name into SCREAMING_SNAKE_CASE.
This macro implements std::fmt::Display for enums where each variant is a unit variant (i.e., no data). It turns the variant name into SCREAMING_SNAKE_CASE at compile time.
use derive_screaming_snake_case::Display;
#[derive(Display)]
enum Status {
Ok,
NotFound,
InternalServerError,
}
fn main() {
assert_eq!(Status::Ok.to_string(), "OK");
assert_eq!(Status::NotFound.to_string(), "NOT_FOUND");
assert_eq!(Status::InternalServerError.to_string(), "INTERNAL_SERVER_ERROR");
}
use derive_screaming_snake_case::Display;
#[derive(Display)]
enum Message {
// ❌ This is NOT a unit variant
Text(String),
// ❌ This is a struct variant
Error { code: u32, message: String },
// ✅ This is fine
Ping,
}
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.