Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jordy25519/casey
Case transforming macros for idents
https://github.com/jordy25519/casey
case-transforming-macros macros rust
Last synced: about 2 months ago
JSON representation
Case transforming macros for idents
- Host: GitHub
- URL: https://github.com/jordy25519/casey
- Owner: jordy25519
- License: mit
- Created: 2019-05-01T05:43:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-15T02:03:21.000Z (over 1 year ago)
- Last Synced: 2024-07-24T22:04:32.223Z (2 months ago)
- Topics: case-transforming-macros, macros, rust
- Language: Rust
- Size: 34.2 KB
- Stars: 34
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# Casey
[![Build](https://github.com/holygits/casey/actions/workflows/build.yml/badge.svg)](https://github.com/holygits/casey/actions/workflows/build.yml)
Case transforming macros
Casey transforms the case of given input `ident`s.
Niche but maybe useful in other macros.
```rust
use casey::{pascal, lower, shouty, snake, upper};lower!(ABC); // renders: `abc`
upper!(abc); // `ABC`
snake!(ABC); // `a_b_c`
pascal!(ab_c); // `AbC`
shouty!(a_b_c); // `A_B_C`
```## Token Stream
Casey macros can operate on `TokenStream`s e.g.
```rust
snake!(
#[derive(PartialEq)]
struct MockStruct {}
impl MockStruct {
fn test() -> bool { true }
}
);
assert!(mock_struct::test());
assert!(mock_struct::test() == mock_struct::test())
```
All `ident` tokens in the stream will have the case transformation applied (keywords and attribute macros will be ignored).### Gotchas
Type names, including built-in types are not considered keywords e.g. `bool`, `usize`, `i32` etc. and **will** be transformed by casey.
```rust
pascal!(let test: bool = true); // renders: `let Test: Bool = true;`
```