8 releases

0.4.0 May 15, 2023
0.3.3 Oct 6, 2020
0.3.2 Sep 30, 2020
0.3.0 Jul 16, 2020
0.1.1 May 7, 2019

#296 in Procedural macros

Download history 1237/week @ 2024-01-05 1443/week @ 2024-01-12 1009/week @ 2024-01-19 989/week @ 2024-01-26 950/week @ 2024-02-02 1138/week @ 2024-02-09 1395/week @ 2024-02-16 1411/week @ 2024-02-23 1709/week @ 2024-03-01 1669/week @ 2024-03-08 1348/week @ 2024-03-15 1667/week @ 2024-03-22 1598/week @ 2024-03-29 1288/week @ 2024-04-05 1868/week @ 2024-04-12 1350/week @ 2024-04-19

6,620 downloads per month
Used in 27 crates (12 directly)

MIT license

9KB
168 lines

Casey

Build

Case transforming macros

Casey transforms the case of given input idents.
Niche but maybe useful in other macros.

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 TokenStreams e.g.

    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.

pascal!(let test: bool = true); // renders: `let Test: Bool = true;`

Dependencies

~1.5MB
~34K SLoC